forked from fengjundev/Android-Skin-Loader
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
fengjun
committed
Aug 6, 2015
1 parent
f4e8487
commit 813cd85
Showing
16 changed files
with
268 additions
and
118 deletions.
There are no files selected for viewing
Empty file.
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
84 changes: 84 additions & 0 deletions
84
lib/src/cn/feng/skin/manager/base/BaseFragmentActivity.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,84 @@ | ||
package cn.feng.skin.manager.base; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
import android.os.Bundle; | ||
import android.support.v4.app.FragmentActivity; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import cn.feng.skin.manager.listener.ISkinUpdate; | ||
import cn.feng.skin.manager.loader.SkinInflaterFactory; | ||
import cn.feng.skin.manager.loader.SkinManager; | ||
|
||
/** | ||
* Base Fragment Activity for development | ||
* | ||
* <p>NOTICE:<br> | ||
* You should extends from this if you what to do skin change | ||
* | ||
* @author fengjun | ||
*/ | ||
public class BaseFragmentActivity extends FragmentActivity implements ISkinUpdate{ | ||
|
||
/** | ||
* Whether response to skin changing after create | ||
*/ | ||
private boolean isResponseOnSkinChanging = true; | ||
|
||
private SkinInflaterFactory mSkinInflaterFactory; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
try { | ||
Field field = LayoutInflater.class.getDeclaredField("mFactorySet"); | ||
field.setAccessible(true); | ||
field.setBoolean(getLayoutInflater(), false); | ||
|
||
mSkinInflaterFactory = new SkinInflaterFactory(); | ||
getLayoutInflater().setFactory(mSkinInflaterFactory); | ||
|
||
} catch (NoSuchFieldException e) { | ||
e.printStackTrace(); | ||
} catch (IllegalArgumentException e) { | ||
e.printStackTrace(); | ||
} catch (IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
SkinManager.getInstance().attach(this); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
SkinManager.getInstance().detach(this); | ||
} | ||
|
||
/** | ||
* dynamic add a skin view | ||
* | ||
* @param view | ||
* @param attrName | ||
* @param attrValueResId | ||
*/ | ||
protected void dynamicAddNewSkinWidget(View view, String attrName, int attrValueResId){ | ||
// developing ... | ||
} | ||
|
||
final protected void enableResponseOnSkinChanging(boolean enable){ | ||
isResponseOnSkinChanging = enable; | ||
} | ||
|
||
@Override | ||
public void onThemeUpdate() { | ||
if(!isResponseOnSkinChanging) return; | ||
mSkinInflaterFactory.applySkin(); | ||
} | ||
} |
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
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
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
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 |
---|---|---|
@@ -1,26 +1,5 @@ | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
xmlns:skin="http://schemas.android.com/android/skin" | ||
android:id="@+id/root_layout" | ||
android:id="@+id/fragment_container" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
skin:enable="true" | ||
android:background="@color/color_app_bg" > | ||
|
||
<include | ||
android:id="@+id/title_bar_layout" | ||
layout="@layout/include_main_title_bar" /> | ||
|
||
<ListView | ||
android:id="@+id/news_list_view" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:layout_below="@id/title_bar_layout" | ||
android:cacheColorHint="#00000000" | ||
android:divider="@color/color_new_list_divider" | ||
android:dividerHeight="1dp" | ||
skin:enable="true" | ||
android:listSelector="@drawable/news_item_selector" | ||
android:scrollbars="none" /> | ||
|
||
</RelativeLayout> | ||
android:layout_height="match_parent" /> |
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
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,26 @@ | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
xmlns:skin="http://schemas.android.com/android/skin" | ||
android:id="@+id/root_layout" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="@color/color_app_bg" | ||
skin:enable="true" > | ||
|
||
<include | ||
android:id="@+id/title_bar_layout" | ||
layout="@layout/include_main_title_bar" /> | ||
|
||
<ListView | ||
android:id="@+id/news_list_view" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:cacheColorHint="#00000000" | ||
android:layout_below="@id/title_bar_layout" | ||
android:divider="@color/color_new_list_divider" | ||
android:dividerHeight="1dp" | ||
android:listSelector="@drawable/news_item_selector" | ||
android:scrollbars="none" | ||
skin:enable="true" /> | ||
|
||
</RelativeLayout> |
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
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
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 |
---|---|---|
@@ -1,94 +1,30 @@ | ||
package cn.feng.skin.demo.activity; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.view.View.OnClickListener; | ||
import android.widget.AbsListView; | ||
import android.widget.AdapterView; | ||
import android.widget.AdapterView.OnItemClickListener; | ||
import android.widget.Button; | ||
import android.widget.ListView; | ||
import android.widget.TextView; | ||
import android.support.v4.app.Fragment; | ||
import android.support.v4.app.FragmentManager; | ||
import cn.feng.skin.demo.R; | ||
import cn.feng.skin.demo.entity.News; | ||
import cn.feng.skin.manager.base.SkinPluginActivity; | ||
import cn.feng.skin.manager.util.CommonBaseAdapter; | ||
import cn.feng.skin.manager.util.CommonViewHolder; | ||
import cn.feng.skin.manager.util.L; | ||
import cn.feng.skin.demo.fragment.ArticleListFragment; | ||
import cn.feng.skin.manager.base.BaseFragmentActivity; | ||
|
||
public class MainActivity extends SkinPluginActivity{ | ||
|
||
private TextView titleText; | ||
private Button settingBtn; | ||
private ListView newsList; | ||
private NewsAdapter adapter; | ||
private List<News> datas; | ||
public class MainActivity extends BaseFragmentActivity{ | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
initData(); | ||
initView(); | ||
} | ||
|
||
private void initData() { | ||
datas = new ArrayList<News>(); | ||
for(int i = 0;i < 10; i++){ | ||
News news = new News(); | ||
news.content = "Always listen to your heart because even though it's on your left side, it's always right."; | ||
news.title = "每日随笔"; | ||
datas.add(news); | ||
} | ||
} | ||
|
||
private void initView() { | ||
titleText = (TextView) findViewById(R.id.title_text); | ||
newsList = (ListView) findViewById(R.id.news_list_view); | ||
settingBtn = (Button) findViewById(R.id.title_bar_setting_btn); | ||
|
||
titleText.setText("Small Article"); | ||
|
||
adapter = new NewsAdapter(this, datas); | ||
|
||
newsList.setAdapter(adapter); | ||
|
||
newsList.setOnItemClickListener(new OnItemClickListener() { | ||
@Override | ||
public void onItemClick(AdapterView<?> parent, View view,int position, long id) { | ||
Intent intent = new Intent(); | ||
intent.setClass(MainActivity.this, DetailActivity.class); | ||
startActivity(intent); | ||
} | ||
}); | ||
|
||
settingBtn.setOnClickListener(new OnClickListener() { | ||
|
||
@Override | ||
public void onClick(View v) { | ||
Intent intent = new Intent(); | ||
intent.setClass(MainActivity.this, SettingActivity.class); | ||
startActivity(intent); | ||
} | ||
}); | ||
initFragment(); | ||
} | ||
|
||
private class NewsAdapter extends CommonBaseAdapter<News>{ | ||
|
||
public NewsAdapter(Context context, List<News> mDatas) { | ||
super(context, mDatas, new int[]{R.layout.item_news_title}); | ||
} | ||
|
||
@Override | ||
public void convertItemView(CommonViewHolder holder, News item, int position) { | ||
holder.setText(R.id.item_news_title, item.title); | ||
holder.setText(R.id.item_news_synopsis, item.content); | ||
private void initFragment() { | ||
FragmentManager fm = getSupportFragmentManager(); | ||
Fragment fragment = fm.findFragmentById(R.id.fragment_container); | ||
if(fragment == null){ | ||
fragment = new ArticleListFragment(); | ||
fm.beginTransaction() | ||
.add(R.id.fragment_container, fragment) | ||
.commit(); | ||
} | ||
} | ||
} |
Oops, something went wrong.