If you think the Android project Viz listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright 2012-2014, First Three LLC//fromwww.java2s.com
*
* This file is a part of Viz.
*
* Viz 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 3 of the License,
* or (at your option) any later version.
*
* Viz 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 Viz. If not, see <http://www.gnu.org/licenses/>.
*/package com.first3.viz.utils;
import android.app.Activity;
import android.os.Bundle;
import android.os.Message;
import android.app.FragmentTransaction;
import android.app.Fragment;
import android.app.FragmentManager;
publicabstractclass ActivityParent extends Activity {
@Override
publicvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
final Fragment state = new State();
final FragmentManager fm = getFragmentManager();
final FragmentTransaction ft = fm.beginTransaction();
ft.add(state, State.TAG);
ft.commit();
}
}
publicabstractvoid processMessage(Message msg);
publicvoid sendMessage(int what, int command, Object obj) {
final FragmentManager fm = getFragmentManager();
State fragment = (State) fm.findFragmentByTag(State.TAG);
if (fragment != null) {
Log.d("sendMessage(what=" + what + ", command=" + command + ")");
fragment.handler.sendMessage(fragment.handler.obtainMessage(what, command, 0, obj));
}
}
/**
* Message Handler class that supports buffering up of messages when the
* activity is paused i.e. in the background and not able to display
* dialogs without crashing.
*/publicstaticclass PauseHandler extends AbstractPauseHandler {
@Override
publicboolean storeMessage(Message message) {
return true;
}
@Override
publicfinalvoid processMessage(Message msg) {
ActivityParent parent = (ActivityParent) this.getActivity();
if (parent != null) {
parent.processMessage(msg);
}
}
}
publicstaticclass State extends Fragment {
publicstaticfinal String TAG = "State";
public State() {
}
/**
* Handler for this activity.
*/public AbstractPauseHandler handler = new PauseHandler();
@Override
publicvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
}
@Override
publicvoid onResume() {
super.onResume();
handler.setActivity(getActivity());
handler.resume();
}
@Override
publicvoid onPause() {
super.onPause();
handler.pause();
}
publicvoid onDestroy() {
super.onDestroy();
handler.setActivity(null);
}
}
}