Converted StepsActivity to Kotlin
This commit is contained in:
parent
8f72a33d2b
commit
40fc651f0d
4 changed files with 120 additions and 141 deletions
|
@ -1,74 +0,0 @@
|
|||
/*
|
||||
* StepsActivity.java
|
||||
*
|
||||
* Copyright 2016 Erik C. Thauvin (erik@thauvin.net)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package net.thauvin.erik.android.tesremoteprogrammer;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.os.Bundle;
|
||||
import android.support.v13.app.FragmentStatePagerAdapter;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
|
||||
import com.viewpagerindicator.UnderlinePageIndicator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class StepsActivity extends FragmentActivity {
|
||||
|
||||
public static final String EXTRA_STEPS = "steps";
|
||||
|
||||
private final ArrayList<String> steps = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_steps);
|
||||
|
||||
steps.clear();
|
||||
steps.addAll(getIntent().getExtras().getStringArrayList(EXTRA_STEPS));
|
||||
|
||||
final ViewPager pager = (ViewPager) findViewById(R.id.pager);
|
||||
final PagerAdapter pagerAdapter = new StepsAdapter(getFragmentManager(), steps);
|
||||
pager.setAdapter(pagerAdapter);
|
||||
final UnderlinePageIndicator pageIndicator = (UnderlinePageIndicator) findViewById(R.id.indicator);
|
||||
pageIndicator.setViewPager(pager, pager.getCurrentItem() - 1);
|
||||
pageIndicator.setFades(false);
|
||||
}
|
||||
|
||||
private class StepsAdapter extends FragmentStatePagerAdapter {
|
||||
private final ArrayList<String> stepsArray = new ArrayList<>();
|
||||
|
||||
public StepsAdapter(FragmentManager fm, ArrayList<String> steps) {
|
||||
super(fm);
|
||||
|
||||
stepsArray.clear();
|
||||
stepsArray.addAll(steps);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
return StepsFragment.create(position, stepsArray);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return stepsArray.size();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* StepsActivity.kt
|
||||
*
|
||||
* Copyright 2016 Erik C. Thauvin (erik@thauvin.net)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package net.thauvin.erik.android.tesremoteprogrammer
|
||||
|
||||
import android.app.Fragment
|
||||
import android.app.FragmentManager
|
||||
import android.os.Bundle
|
||||
import android.support.v13.app.FragmentStatePagerAdapter
|
||||
import android.support.v4.app.FragmentActivity
|
||||
import android.support.v4.view.ViewPager
|
||||
import com.viewpagerindicator.UnderlinePageIndicator
|
||||
import java.util.*
|
||||
|
||||
class StepsActivity : FragmentActivity() {
|
||||
companion object {
|
||||
val EXTRA_STEPS = "steps"
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_steps)
|
||||
|
||||
val pager = findViewById(R.id.pager) as ViewPager
|
||||
pager.adapter = StepsAdapter(fragmentManager, intent.extras.getStringArrayList(EXTRA_STEPS))
|
||||
val pageIndicator = findViewById(R.id.indicator) as UnderlinePageIndicator
|
||||
pageIndicator.setViewPager(pager, pager.currentItem - 1)
|
||||
pageIndicator.fades = false
|
||||
}
|
||||
|
||||
private inner class StepsAdapter(fm: FragmentManager,
|
||||
steps: ArrayList<String>) : FragmentStatePagerAdapter(fm) {
|
||||
private val steps = ArrayList<String>(steps)
|
||||
|
||||
override fun getItem(position: Int): Fragment {
|
||||
return StepsFragment.create(position, steps)
|
||||
}
|
||||
|
||||
override fun getCount(): Int {
|
||||
return steps.size
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
/*
|
||||
* StepsFragment.java
|
||||
*
|
||||
* Copyright 2016 Erik C. Thauvin (erik@thauvin.net)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package net.thauvin.erik.android.tesremoteprogrammer;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class StepsFragment extends Fragment {
|
||||
public static final String ARG_PAGE = "page";
|
||||
private static final ArrayList<String> stepsArray = new ArrayList<>();
|
||||
private int pageNumber;
|
||||
|
||||
public StepsFragment() {
|
||||
}
|
||||
|
||||
public static StepsFragment create(int pageNumber, ArrayList<String> steps) {
|
||||
final StepsFragment fragment = new StepsFragment();
|
||||
Bundle args = new Bundle();
|
||||
|
||||
args.putInt(ARG_PAGE, pageNumber);
|
||||
fragment.setArguments(args);
|
||||
|
||||
stepsArray.clear();
|
||||
stepsArray.addAll(steps);
|
||||
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
pageNumber = getArguments().getInt(ARG_PAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
final ViewGroup rootView = (ViewGroup) inflater
|
||||
.inflate(R.layout.fragment_steps, container, false);
|
||||
|
||||
((TextView) rootView.findViewById(R.id.frag_steps_title)).setText(
|
||||
getString(R.string.title_template_step, pageNumber + 1, stepsArray.size()));
|
||||
((TextView) rootView.findViewById(R.id.frag_steps)).setText(stepsArray.get(pageNumber));
|
||||
return rootView;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* StepsFragment.kt
|
||||
*
|
||||
* Copyright 2016 Erik C. Thauvin (erik@thauvin.net)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package net.thauvin.erik.android.tesremoteprogrammer
|
||||
|
||||
import android.app.Fragment
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import java.util.*
|
||||
|
||||
class StepsFragment : Fragment() {
|
||||
private var pageNumber: Int = 0
|
||||
|
||||
companion object {
|
||||
val ARG_PAGE = "page"
|
||||
private val steps = ArrayList<String>()
|
||||
|
||||
fun create(pageNumber: Int, steps: ArrayList<String>): StepsFragment {
|
||||
val fragment = StepsFragment()
|
||||
val args = Bundle()
|
||||
|
||||
args.putInt(ARG_PAGE, pageNumber)
|
||||
fragment.arguments = args
|
||||
|
||||
this.steps.clear()
|
||||
this.steps.addAll(steps)
|
||||
|
||||
return fragment
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
pageNumber = arguments.getInt(ARG_PAGE)
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?): View? {
|
||||
val rootView = inflater.inflate(R.layout.fragment_steps, container, false) as ViewGroup
|
||||
|
||||
(rootView.findViewById(R.id.frag_steps_title) as TextView).text =
|
||||
getString(R.string.title_template_step, pageNumber + 1, steps.size)
|
||||
(rootView.findViewById(R.id.frag_steps) as TextView).text = steps[pageNumber]
|
||||
return rootView
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue