mirror of
https://github.com/gsantner/dandelion
synced 2025-12-15 08:41:10 +01:00
Added first design of an AboutActivity
This commit is contained in:
parent
12d12cdd39
commit
0b8dbcc35d
19 changed files with 326 additions and 15 deletions
|
|
@ -0,0 +1,165 @@
|
|||
package com.github.dfa.diaspora_android.activity;
|
||||
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.TabLayout;
|
||||
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.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.Html;
|
||||
import android.text.SpannableString;
|
||||
import android.text.util.Linkify;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.github.dfa.diaspora_android.R;
|
||||
|
||||
public class AboutActivity extends AppCompatActivity {
|
||||
|
||||
/**
|
||||
* The {@link android.support.v4.view.PagerAdapter} that will provide
|
||||
* fragments for each of the sections. We use a
|
||||
* {@link FragmentPagerAdapter} derivative, which will keep every
|
||||
* loaded fragment in memory. If this becomes too memory intensive, it
|
||||
* may be best to switch to a
|
||||
* {@link android.support.v4.app.FragmentStatePagerAdapter}.
|
||||
*/
|
||||
private SectionsPagerAdapter mSectionsPagerAdapter;
|
||||
|
||||
/**
|
||||
* The {@link ViewPager} that will host the section contents.
|
||||
*/
|
||||
private ViewPager mViewPager;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_about);
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
// Create the adapter that will return a fragment for each of the three
|
||||
// primary sections of the activity.
|
||||
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
||||
|
||||
// Set up the ViewPager with the sections adapter.
|
||||
mViewPager = (ViewPager) findViewById(R.id.container);
|
||||
mViewPager.setAdapter(mSectionsPagerAdapter);
|
||||
|
||||
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
|
||||
tabLayout.setupWithViewPager(mViewPager);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Fragment that shows information about the app
|
||||
*/
|
||||
public static class AboutFragment extends Fragment {
|
||||
|
||||
public AboutFragment() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.fragment_about, container, false);
|
||||
TextView packageName = (TextView) rootView.findViewById(R.id.fragment_about__package_name);
|
||||
TextView appVersion = (TextView) rootView.findViewById(R.id.fragment_about__app_version);
|
||||
|
||||
if(isAdded()) {
|
||||
try {
|
||||
PackageInfo pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
|
||||
|
||||
packageName.setText(pInfo.packageName);
|
||||
appVersion.setText(getString(R.string.fragment_about__app_version, pInfo.versionName+ " ("+pInfo.versionCode+")"));
|
||||
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return rootView;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fragment that shows information about the app
|
||||
*/
|
||||
public static class LicenseFragment extends Fragment {
|
||||
|
||||
public LicenseFragment() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.fragment_license, container, false);
|
||||
return rootView;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fragment that shows information about the app
|
||||
*/
|
||||
public static class DebugFragment extends Fragment {
|
||||
|
||||
public DebugFragment() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.fragment_about, container, false);
|
||||
((TextView) rootView.findViewById(R.id.debug_text)).setText("Debug");
|
||||
return rootView;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
|
||||
* one of the sections/tabs/pages.
|
||||
*/
|
||||
public class SectionsPagerAdapter extends FragmentPagerAdapter {
|
||||
|
||||
public SectionsPagerAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
switch (position) {
|
||||
case 0: //About
|
||||
return new AboutFragment();
|
||||
case 1: //License
|
||||
return new LicenseFragment();
|
||||
case 3: //Debug
|
||||
default:
|
||||
return new DebugFragment();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
// Show 3 total pages.
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
switch (position) {
|
||||
case 0:
|
||||
return getString(R.string.about_activity__title_about_app);
|
||||
case 1:
|
||||
return getString(R.string.about_activity__title_about_license);
|
||||
case 2:
|
||||
return getString(R.string.about_activity__title_debug_info);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -768,6 +768,9 @@ public class MainActivity extends AppCompatActivity
|
|||
}
|
||||
return true;
|
||||
}
|
||||
case R.id.debug: {
|
||||
startActivity(new Intent(this, AboutActivity.class));
|
||||
}
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
|
@ -1049,14 +1052,14 @@ public class MainActivity extends AppCompatActivity
|
|||
break;
|
||||
|
||||
case R.id.nav_help_license: {
|
||||
final CharSequence[] options = {getString(R.string.help_license__name), getString(R.string.help_markdown__name)};
|
||||
final CharSequence[] options = {getString(R.string.about_activity__title_about_license), getString(R.string.help_markdown__name)};
|
||||
new AlertDialog.Builder(MainActivity.this)
|
||||
.setItems(options, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int item) {
|
||||
if (options[item].equals(getString(R.string.help_license__name))) {
|
||||
if (options[item].equals(getString(R.string.about_activity__title_about_license))) {
|
||||
|
||||
final SpannableString s = new SpannableString(Html.fromHtml(getString(R.string.help_license__content)));
|
||||
final SpannableString s = new SpannableString(Html.fromHtml(getString(R.string.fragment_license__license_content)));
|
||||
Linkify.addLinks(s, Linkify.WEB_URLS);
|
||||
final AlertDialog d = new AlertDialog.Builder(MainActivity.this)
|
||||
.setTitle(R.string.help_license__years)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
package com.github.dfa.diaspora_android.ui;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.text.Html;
|
||||
import android.text.SpannableString;
|
||||
import android.text.util.Linkify;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.github.dfa.diaspora_android.R;
|
||||
|
||||
public class HtmlTextView extends TextView {
|
||||
|
||||
public HtmlTextView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public HtmlTextView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public HtmlTextView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
|
||||
@TargetApi(21)
|
||||
public HtmlTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init(){
|
||||
final SpannableString content = new SpannableString(Html.fromHtml(getText().toString()));
|
||||
Linkify.addLinks(content, Linkify.WEB_URLS);
|
||||
setText(content);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue