-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#59: defined new Activity to display color details
- Loading branch information
Showing
3 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
android-rgb-tool/src/main/java/com/fastebro/androidrgbtool/ui/ColorDetailsActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package com.fastebro.androidrgbtool.ui; | ||
|
||
import android.support.design.widget.TabLayout; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.Toolbar; | ||
|
||
import android.support.v4.app.Fragment; | ||
import android.support.v4.app.FragmentManager; | ||
import android.support.v4.app.FragmentPagerAdapter; | ||
import android.support.v4.view.ViewPager; | ||
import android.os.Bundle; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import android.widget.TextView; | ||
|
||
import com.fastebro.androidrgbtool.R; | ||
|
||
public class ColorDetailsActivity extends AppCompatActivity { | ||
|
||
private SectionsPagerAdapter sectionsPagerAdapter; | ||
private ViewPager viewPager; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_color_details); | ||
|
||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | ||
setSupportActionBar(toolbar); | ||
|
||
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); | ||
viewPager = (ViewPager) findViewById(R.id.container); | ||
viewPager.setAdapter(sectionsPagerAdapter); | ||
|
||
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); | ||
tabLayout.setupWithViewPager(viewPager); | ||
} | ||
|
||
/** | ||
* A placeholder fragment containing a simple view. | ||
*/ | ||
public static class PlaceholderFragment extends Fragment { | ||
/** | ||
* The fragment argument representing the section number for this | ||
* fragment. | ||
*/ | ||
private static final String ARG_SECTION_NUMBER = "section_number"; | ||
|
||
public PlaceholderFragment() { | ||
} | ||
|
||
/** | ||
* Returns a new instance of this fragment for the given section | ||
* number. | ||
*/ | ||
public static PlaceholderFragment newInstance(int sectionNumber) { | ||
PlaceholderFragment fragment = new PlaceholderFragment(); | ||
Bundle args = new Bundle(); | ||
args.putInt(ARG_SECTION_NUMBER, sectionNumber); | ||
fragment.setArguments(args); | ||
return fragment; | ||
} | ||
|
||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||
Bundle savedInstanceState) { | ||
View rootView = inflater.inflate(R.layout.fragment_color_details, container, false); | ||
TextView textView = (TextView) rootView.findViewById(R.id.section_label); | ||
textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER))); | ||
return rootView; | ||
} | ||
} | ||
|
||
public class SectionsPagerAdapter extends FragmentPagerAdapter { | ||
|
||
public SectionsPagerAdapter(FragmentManager fm) { | ||
super(fm); | ||
} | ||
|
||
@Override | ||
public Fragment getItem(int position) { | ||
// getItem is called to instantiate the fragment for the given page. | ||
// Return a PlaceholderFragment (defined as a static inner class below). | ||
return PlaceholderFragment.newInstance(position + 1); | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
// Show 3 total pages. | ||
return 3; | ||
} | ||
|
||
@Override | ||
public CharSequence getPageTitle(int position) { | ||
switch (position) { | ||
case 0: | ||
return "SECTION 1"; | ||
case 1: | ||
return "SECTION 2"; | ||
case 2: | ||
return "SECTION 3"; | ||
} | ||
return null; | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
android-rgb-tool/src/main/res/layout/activity_color_details.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.design.widget.CoordinatorLayout android:id="@+id/main_content" | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:fitsSystemWindows="true" | ||
tools:context="com.fastebro.androidrgbtool.ui.ColorDetailsActivity"> | ||
|
||
<android.support.design.widget.AppBarLayout | ||
android:id="@+id/appbar" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:paddingTop="@dimen/appbar_padding_top" | ||
android:theme="@style/Theme.Rgbtool.AppBarOverlay"> | ||
|
||
<android.support.v7.widget.Toolbar | ||
android:id="@+id/toolbar" | ||
android:layout_width="match_parent" | ||
android:layout_height="?attr/actionBarSize" | ||
android:background="?attr/colorPrimary" | ||
app:layout_scrollFlags="scroll|enterAlways" | ||
app:popupTheme="@style/Theme.Rgbtool.PopupOverlay"> | ||
|
||
</android.support.v7.widget.Toolbar> | ||
|
||
<android.support.design.widget.TabLayout | ||
android:id="@+id/tabs" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"/> | ||
|
||
</android.support.design.widget.AppBarLayout> | ||
|
||
<android.support.v4.view.ViewPager | ||
android:id="@+id/container" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
app:layout_behavior="@string/appbar_scrolling_view_behavior"/> | ||
|
||
</android.support.design.widget.CoordinatorLayout> |
16 changes: 16 additions & 0 deletions
16
android-rgb-tool/src/main/res/layout/fragment_color_details.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:paddingBottom="@dimen/activity_vertical_margin" | ||
android:paddingLeft="@dimen/activity_horizontal_margin" | ||
android:paddingRight="@dimen/activity_horizontal_margin" | ||
android:paddingTop="@dimen/activity_vertical_margin" | ||
tools:context="com.fastebro.androidrgbtool.ui.ColorDetailsActivity$PlaceholderFragment"> | ||
|
||
<TextView | ||
android:id="@+id/section_label" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content"/> | ||
|
||
</RelativeLayout> |