Commit 83c77546 authored by Adrien Maglo's avatar Adrien Maglo
Browse files

About fragment: transform the about activity into a fragment for a better integration

The new fragment has also sliding tabs as in the audio albums songs fragment.
parent 70ee34ca
......@@ -6,60 +6,38 @@
android:orientation="vertical"
android:weightSum="1" >
<RelativeLayout
<TabHost
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="70dip"
android:layout_gravity="top"
android:background="@drawable/actionbar_background"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="69dip"
android:layout_height="50dip"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/cone" />
android:layout_height="fill_parent" >
<ImageView
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imageView1"
android:scaleType="centerInside"
android:src="@drawable/header_logo" />
android:orientation="vertical" >
<TextView
android:id="@+id/textViewVersion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="8dp"
android:layout_marginBottom="4dp"
android:gravity="center"
android:textColor="@android:color/white"
android:textSize="18sp" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="?attr/background_menu" />
</RelativeLayout>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<org.videolan.vlc.widget.FlingViewGroup
android:id="@+id/fling_view_group"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<include layout="@layout/about_main" />
<include layout="@layout/about_licence" />
</org.videolan.vlc.widget.FlingViewGroup>
</FrameLayout>
</LinearLayout>
</TabHost>
<TabHost
android:id="@+id/about_tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="?attr/background_menu" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
</TabHost>
</LinearLayout>
/*****************************************************************************
* AboutActivity.java
*****************************************************************************
* Copyright © 2011-2012 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
package org.videolan.vlc.gui;
import org.videolan.vlc.R;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TextView;
public class AboutActivity extends FragmentActivity implements OnTabChangeListener {
public final static String TAG = "VLC/AboutActivity";
private final static String CURRENT_TAB_TAG = "tabtag";
private final static String CURRENT_TAB_ID = "tabid";
private class DummyContentFactory implements TabHost.TabContentFactory {
private final Context mContext;
public DummyContentFactory(Context ctx) {
mContext = ctx;
}
@Override
public View createTabContent(String tag) {
View dummy = new View(mContext);
dummy.setMinimumHeight(0);
dummy.setMinimumWidth(0);
return dummy;
}
}
private TabHost mTabHost;
private String mCurrentTabTag;
private AboutMainFragment mMainFragment;
private AboutLicenceFragment mLicenceFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about);
displayVersionName();
mMainFragment = new AboutMainFragment();
mLicenceFragment = new AboutLicenceFragment();
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.add(android.R.id.tabcontent, mMainFragment);
ft.add(android.R.id.tabcontent, mLicenceFragment);
ft.commit();
DummyContentFactory dcf = new DummyContentFactory(this);
mTabHost = (TabHost)findViewById(R.id.about_tabhost);
mTabHost.setup();
TabHost.TabSpec tab_main = mTabHost.newTabSpec("main");
tab_main.setContent(dcf);
tab_main.setIndicator(getNewTabIndicator(mTabHost.getContext(),
getResources().getText(R.string.about).toString()));
mTabHost.addTab(tab_main);
TabHost.TabSpec tab_licence = mTabHost.newTabSpec("licence");
tab_licence.setContent(dcf);
tab_licence.setIndicator(getNewTabIndicator(mTabHost.getContext(),
getResources().getText(R.string.licence).toString()));
mTabHost.addTab(tab_licence);
mTabHost.setOnTabChangedListener(this);
this.onTabChanged("main");
if (savedInstanceState != null) {
mTabHost.setCurrentTab(savedInstanceState.getInt(CURRENT_TAB_ID));
this.onTabChanged(savedInstanceState.getString(CURRENT_TAB_TAG));
}
}
private View getNewTabIndicator(Context context, String title) {
View v = LayoutInflater.from(context).inflate(R.layout.tab_layout, null);
TextView tv = (TextView) v.findViewById(R.id.textView);
tv.setText(title);
return v;
}
protected void onSaveInstanceState(Bundle outState) {
outState.putString(CURRENT_TAB_TAG, mCurrentTabTag);
outState.putInt(CURRENT_TAB_ID, mTabHost.getCurrentTab());
}
@Override
public void onTabChanged(String newTag) {
String oldTag = mCurrentTabTag; /* cosmetics */
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
if(oldTag == "main" && newTag == "licence") {
ft.setCustomAnimations(R.anim.anim_enter_right, R.anim.anim_leave_left);
} else if(newTag == "main" && oldTag == "licence") {
ft.setCustomAnimations(R.anim.anim_enter_left, R.anim.anim_leave_right);
}
ft.detach(getFragmentFromTag(oldTag));
ft.attach(getFragmentFromTag(newTag));
ft.commit();
mCurrentTabTag = newTag;
}
private Fragment getFragmentFromTag(String tag) {
if(tag == "main")
return mMainFragment;
else
return mLicenceFragment;
}
private void displayVersionName() {
String versionName = getVersion(this);
TextView tv = (TextView) findViewById(R.id.textViewVersion);
tv.setText(versionName);
}
public static String getVersion(Context ctx) {
String versionName = "";
PackageInfo packageInfo;
try {
packageInfo = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0);
versionName = "v" + packageInfo.versionName;
} catch (NameNotFoundException e) {
e.printStackTrace();
}
return versionName;
}
}
/*****************************************************************************
* AboutMainFragment.java
* AboutActivity.java
*****************************************************************************
* Copyright © 2012 VLC authors and VideoLAN
* Copyright © 2012 Edward Wang
* Copyright © 2011-2012 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -18,41 +17,60 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
package org.videolan.vlc.gui;
import org.videolan.vlc.R;
import org.videolan.vlc.Util;
import org.videolan.vlc.widget.FlingViewGroup;
import com.actionbarsherlock.app.SherlockFragment;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.RotateAnimation;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;
public class AboutMainFragment extends Fragment {
public final static String TAG = "VLC/AboutMainFragment";
public class AboutFragment extends SherlockFragment {
public final static String TAG = "VLC/AboutActivity";
private TabHost mTabHost;
FlingViewGroup mFlingViewGroup;
private int mCurrentTab = 0;
/* All subclasses of Fragment must include a public empty constructor. */
public AboutMainFragment() { }
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View v = inflater.inflate(R.layout.about_main, container, false);
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
getSherlockActivity().getSupportActionBar().setTitle("VLC " + getVersion(getActivity()));
View v = inflater.inflate(R.layout.about, container, false);
mTabHost = (TabHost) v.findViewById(android.R.id.tabhost);
mFlingViewGroup = (FlingViewGroup) v.findViewById(R.id.fling_view_group);
WebView t = (WebView)v.findViewById(R.id.webview);
String revision = Util.readAsset("revision.txt", "Unknown revision");
t.loadData(Util.readAsset("licence.htm", "").replace("!COMMITID!",revision), "text/html", "UTF8");
TextView link = (TextView) v.findViewById(R.id.main_link);
link.setText(Html.fromHtml(this.getString(R.string.about_link)));
String builddate = Util.readAsset("builddate.txt", "Unknown");
String builder = Util.readAsset("builder.txt", "unknown");
String revision = Util.readAsset("revision.txt", "unknown");
TextView compiled = (TextView) v.findViewById(R.id.main_compiled);
compiled.setText(builder + " (" + builddate + ")");
......@@ -72,6 +90,73 @@ public class AboutMainFragment extends Fragment {
}
});
mTabHost.setup();
addNewTab(mTabHost, "about", getResources().getString(R.string.about));
addNewTab(mTabHost, "licence", getResources().getString(R.string.licence));
mTabHost.setCurrentTab(mCurrentTab);
mTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
mCurrentTab = mTabHost.getCurrentTab();
mFlingViewGroup.smoothScrollTo(mCurrentTab);
}
});
mFlingViewGroup.setOnViewSwitchedListener(new FlingViewGroup.ViewSwitchListener() {
@Override
public void onSwitching(float progress) { }
@Override
public void onSwitched(int position) {
mTabHost.setCurrentTab(position);
}
@Override
public void onTouchDown() {}
@Override
public void onTouchUp() {}
});
return v;
}
private class DummyContentFactory implements TabHost.TabContentFactory {
private final Context mContext;
public DummyContentFactory(Context ctx) {
mContext = ctx;
}
@Override
public View createTabContent(String tag) {
View dummy = new View(mContext);
return dummy;
}
}
private void addNewTab(TabHost tabHost, String tag, String title) {
DummyContentFactory dcf = new DummyContentFactory(tabHost.getContext());
TabSpec tabSpec = tabHost.newTabSpec(tag);
tabSpec.setIndicator(getNewTabIndicator(tabHost.getContext(), title));
tabSpec.setContent(dcf);
tabHost.addTab(tabSpec);
}
private View getNewTabIndicator(Context context, String title) {
View v = LayoutInflater.from(context).inflate(R.layout.tab_layout, null);
TextView tv = (TextView) v.findViewById(R.id.textView);
tv.setText(title);
return v;
}
public static String getVersion(Context ctx) {
String versionName = "";
PackageInfo packageInfo;
try {
packageInfo = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0);
versionName = "v" + packageInfo.versionName;
} catch (NameNotFoundException e) {
e.printStackTrace();
}
return versionName;
}
}
/*****************************************************************************
* AboutLicenceFragment.java
*****************************************************************************
* Copyright © 2012 VLC authors and VideoLAN
* Copyright © 2012 Edward Wang
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
package org.videolan.vlc.gui;
import org.videolan.vlc.R;
import org.videolan.vlc.Util;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
public class AboutLicenceFragment extends Fragment {
public final static String TAG = "VLC/AboutLicenceFragment";
/* All subclasses of Fragment must include a public empty constructor. */
public AboutLicenceFragment() { }
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
super.onCreateView(inflater, container, savedInstanceState);
View v = inflater.inflate(R.layout.about_licence, container, false);
String revision = Util.readAsset("revision.txt", "Unknown revision");
WebView t = (WebView)v.findViewById(R.id.webview);
t.loadData(Util.readAsset("licence.htm", "").replace("!COMMITID!",revision), "text/html", "UTF8");
return v;
}
}
\ No newline at end of file
......@@ -114,7 +114,7 @@ public class MainActivity extends SherlockFragmentActivity {
private View mAudioPlayerFilling;
private String mCurrentFragment;
private String mPreviousFragment;
private List<String> secondaryFragments = Arrays.asList("albumsSongs", "equalizer");
private List<String> secondaryFragments = Arrays.asList("albumsSongs", "equalizer", "about");
private HashMap<String, Fragment> mSecondaryFragments = new HashMap<String, Fragment>();
private SharedPreferences mSettings;
......@@ -481,6 +481,8 @@ public class MainActivity extends SherlockFragmentActivity {
f = new AudioAlbumsSongsFragment();
} else if(id.equals("equalizer")) {
f = new EqualizerFragment();
} else if(id.equals("about")) {
f = new AboutFragment();
}
else {
throw new IllegalArgumentException("Wrong fragment id.");
......@@ -579,8 +581,7 @@ public class MainActivity extends SherlockFragmentActivity {
break;
// About
case R.id.ml_menu_about:
intent = new Intent(this, AboutActivity.class);
startActivity(intent);
showSecondaryFragment("about");
break;
// Preferences
case R.id.ml_menu_preferences:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment