1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-12-22 19:08:03 +01:00

Added first design of an AboutActivity

This commit is contained in:
vanitasvitae 2016-08-24 22:05:35 +02:00
parent 12d12cdd39
commit 0b8dbcc35d
19 changed files with 326 additions and 15 deletions

View file

@ -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;
}
}
}

View file

@ -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)

View file

@ -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);
}
}

View file

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.github.dfa.diaspora_android.activity.AboutActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</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>

View file

@ -0,0 +1,33 @@
<android.support.v4.widget.NestedScrollView 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.github.dfa.diaspora_android.activity.AboutActivity$AboutFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/debug_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/diaspora_for_android"
style="@android:style/TextAppearance.DeviceDefault.Large"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/fragment_about__package_name"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/fragment_about__app_version"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>

View file

@ -0,0 +1,24 @@
<android.support.v4.widget.NestedScrollView 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.github.dfa.diaspora_android.activity.AboutActivity$LicenseFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.github.dfa.diaspora_android.ui.HtmlTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/fragment_license__license_content"
android:text="@string/fragment_license__license_content"
android:linksClickable="true"
android:autoLink="web"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>

View file

@ -47,5 +47,9 @@
android:icon="@drawable/ic_sync_white_48px"
android:title="@string/action_exit_app"
app:showAsAction="never" />
<item
android:id="@+id/debug"
android:title="DEBUG"
app:showAsAction="never" />
</menu>

View file

@ -74,5 +74,5 @@
<string name="permission_granted_try_again">Berechtigung erteilt. Bitte versuche es erneut.</string>
<!-- License & help (large amount of text) -->
<string name="help_markdown__name">Markdown Formatierung</string>
<string name="help_license__name">Lizenz</string>
<string name="about_activity__title_about_license">Lizenz</string>
</resources>

View file

@ -66,5 +66,5 @@
<string name="permission_granted_try_again">Permiso concedido. Por favor, inténtelo de nuevo.</string>
<!-- License & help (large amount of text) -->
<string name="help_markdown__name">Formato Markdown</string>
<string name="help_license__name">Licencia</string>
<string name="about_activity__title_about_license">Licencia</string>
</resources>

View file

@ -66,5 +66,5 @@
<string name="permission_granted_try_again">Permission accordée. Veuillez réessayer.</string>
<!-- License & help (large amount of text) -->
<string name="help_markdown__name">Mise en forme Markdown</string>
<string name="help_license__name">Licence</string>
<string name="about_activity__title_about_license">Licence</string>
</resources>

View file

@ -71,5 +71,5 @@
<string name="permission_granted_try_again">Permesso garantito. Si prega di riprovare.</string>
<!-- License & help (large amount of text) -->
<string name="help_markdown__name">Formattazione Markdown</string>
<string name="help_license__name">Licenza</string>
<string name="about_activity__title_about_license">Licenza</string>
</resources>

View file

@ -66,5 +66,5 @@
<string name="permission_granted_try_again">アクセスを許可しました。もう一度やり直してください。</string>
<!-- License & help (large amount of text) -->
<string name="help_markdown__name">マークダウン書式</string>
<string name="help_license__name">ライセンス</string>
<string name="about_activity__title_about_license">ライセンス</string>
</resources>

View file

@ -23,5 +23,5 @@
<string name="all_tags">ಎಲ್ಲಾ ಟ್ಯಾಗ್‌ಗಳು</string>
<!-- Permissions -->
<!-- License & help (large amount of text) -->
<string name="help_license__name">ಪರವಾನಿಗೆ</string>
<string name="about_activity__title_about_license">ಪರವಾನಿಗೆ</string>
</resources>

View file

@ -64,5 +64,5 @@
<string name="permission_granted_try_again">Toestemming verleend. Probeer het opnieuw.</string>
<!-- License & help (large amount of text) -->
<string name="help_markdown__name">Markdown opmaak</string>
<string name="help_license__name">Licentie</string>
<string name="about_activity__title_about_license">Licentie</string>
</resources>

View file

@ -66,5 +66,5 @@
<string name="permission_granted_try_again">Permissão concedida. Por favor, tente novamente.</string>
<!-- License & help (large amount of text) -->
<string name="help_markdown__name">Formatação de markdown</string>
<string name="help_license__name">Licença</string>
<string name="about_activity__title_about_license">Licença</string>
</resources>

View file

@ -66,5 +66,5 @@
<string name="permission_granted_try_again">Разрешение получено. Пожалуйста, попробуйте еще раз.</string>
<!-- License & help (large amount of text) -->
<string name="help_markdown__name">Форматирование Markdown</string>
<string name="help_license__name">Лицензия</string>
<string name="about_activity__title_about_license">Лицензия</string>
</resources>

View file

@ -4,6 +4,6 @@
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:statusBarColor">@color/colorPrimary</item>
</style>
</resources>

View file

@ -5,4 +5,6 @@
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_horizontal_margin_half">8dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="fab_margin">16dp</dimen>
<dimen name="appbar_padding_top">8dp</dimen>
</resources>

View file

@ -1,6 +1,7 @@
<resources>
<!-- App - AppName specific -->
<string name="diaspora" translatable="false">Diaspora</string>
<string name="diaspora_for_android" translatable="false">Diaspora for Android</string>
<string name="app_name" translatable="false">@string/diaspora</string>
<string name="app_hashtag" translatable="false">#DiasporaForAndroid</string>
<string name="app_copyright" translatable="false">The community-run distributed social network</string>
@ -107,9 +108,8 @@
<!-- License & help (large amount of text) -->
<string name="help_markdown__name">Markdown formatting</string>
<string name="help_markdown__weblink" translatable="false">https://wiki.diasporafoundation.org/Markdown_reference_guide</string>
<string name="help_license__name">License</string>
<string name="help_license__years" translatable="false">Copyright © 20152016</string>
<string name="help_license__content" translatable="false">&lt;b>Maintainers:&lt;/b>&lt;br>
<string name="fragment_license__license_content" translatable="false">&lt;b>Maintainers:&lt;/b>&lt;br>
&#8226; gsantner https://gsantner.github.io&lt;br>
&#8226; vanitasvitae https://github.com/vanitasvitae&lt;br> &lt;br>
@ -130,5 +130,11 @@
&lt;i>The splashscreen images can be found on flickr:
https://www.flickr.com/photos/129581906@N06/sets/72157651933980136/with/16594947123.
They were published by \"Lydia\" and are licensed under cc by-nc-sa.&lt;/i></string>
<string name="about_activity__title_about_app">About</string>
<string name="about_activity__title_about_license">License</string>
<string name="about_activity__title_debug_info">Debugging</string>
<string name="fragment_about__app_version">App Version: %1$s</string>
<string name="fragment_about__package_name">Package Name: %1$s</string>
</resources>