Android Open Source - saostar Main Activity From Project Back to project page saostar .
License The source code is released under:
Apache License
If you think the Android project saostar 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 package net.azyobuzi.azyotter.saostar.activities;
/ / f r o m w w w . j a v a 2 s . c o m
import net.azyobuzi.azyotter.saostar.R;
import net.azyobuzi.azyotter.saostar.StringUtil;
import net.azyobuzi.azyotter.saostar.configuration.Accounts;
import net.azyobuzi.azyotter.saostar.configuration.Setting;
import net.azyobuzi.azyotter.saostar.configuration.Tab;
import net.azyobuzi.azyotter.saostar.configuration.Tabs;
import net.azyobuzi.azyotter.saostar.services.UpdateStatusService;
import net.azyobuzi.azyotter.saostar.system.Action1;
import net.azyobuzi.azyotter.saostar.system.Action2;
import net.azyobuzi.azyotter.saostar.system.Action3;
import net.azyobuzi.azyotter.saostar.widget.AccountSelector;
import android.app.ActionBar;
import android.app.ActionBar.TabListener;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
public static final String CALLED_FROM_AZYOTTER = "net.azyobuzi.azyotter.saostar.activities.MainActivity.CALLED_FROM_AZYOTTER" ;
public static final String TAB_INDEX = "net.azyobuzi.azyotter.saostar.activities.MainActivity.TAB_INDEX" ;
private boolean tabChanged = false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(Setting.getTheme());
setContentView(R.layout.main);
if (Accounts.getAccountsCount() == 0) {
startActivity(new Intent(this , AccountsActivity.class)
.putExtra(AccountsActivity.FIRST_RUN, true)
.putExtra(CALLED_FROM_AZYOTTER, true));
finish();
return ;
}
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
createTabs();
Tabs.addedHandler.add(tabChangedHandler);
Tabs.removedHandler.add(tabChangedHandler);
Tabs.movedHandler.add(movedTabHandler);
if (savedInstanceState != null) {
int index = savedInstanceState.getInt(TAB_INDEX, -1);
if (index != -1)
actionBar.selectTab(actionBar.getTabAt(index));
}
findViewById(R.id.btn_main_update_status).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
EditText tweetBox = (EditText)findViewById(R.id.txt_main_tweet);
String text = tweetBox.getText().toString();
if (StringUtil.isNullOrEmpty(text)) return ;
startService(new Intent(MainActivity.this, UpdateStatusService.class)
.putExtra(UpdateStatusService.TEXT, text));
tweetBox.setText("" );
}
});
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
ActionBar.Tab selectedTab = getActionBar().getSelectedTab();
if (selectedTab != null)
outState.putInt(TAB_INDEX, Tabs.indexOf((Tab)selectedTab.getTag()));
}
@Override
public void onDestroy() {
((AccountSelector)findViewById(R.id.as_main)).dispose();
Tabs.addedHandler.remove(tabChangedHandler);
Tabs.removedHandler.remove(tabChangedHandler);
Tabs.movedHandler.remove(movedTabHandler);
super.onDestroy();
}
@Override
protected void onResume() {
super.onResume();
if (tabChanged) {
getActionBar().removeAllTabs();
createTabs();
}
}
private void createTabs() {
final ActionBar actionBar = getActionBar();
Tabs.getAllTabs().forEach(new Action2<Tab, Integer >() {
@Override
public void invoke(Tab arg0, Integer arg1) {
actionBar.addTab(
actionBar.newTab()
.setText(arg0.getName())
.setTabListener(new TimelineTabListener(arg0))
.setTag(arg0)
);
}
});
}
private final Action1<Tab> tabChangedHandler = new Action1<Tab>() {
@Override
public void invoke(Tab arg) {
tabChanged = true;
}
};
private final Action3<Tab, Integer , Integer > movedTabHandler = new Action3<Tab, Integer , Integer >() {
@Override
public void invoke(Tab arg0, Integer arg1, Integer arg2) {
tabChanged = true;
}
};
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_main_update_status:
startActivity(new Intent(this , UpdateStatusActivity.class).putExtra(CALLED_FROM_AZYOTTER, true));
return true;
case R.id.menu_main_tabs:
startActivity(new Intent(this , TabsActivity.class).putExtra(CALLED_FROM_AZYOTTER, true));
return true;
case R.id.menu_main_preference:
startActivity(new Intent(this , SettingActivity.class).putExtra(CALLED_FROM_AZYOTTER, true));
return true;
default :
return super.onOptionsItemSelected(item);
}
}
private class TimelineTabListener implements TabListener {
public TimelineTabListener(Tab tab) {
mFragment = new TimelineTabFragment(tab);
}
private TimelineTabFragment mFragment;
@Override
public void onTabReselected(ActionBar.Tab arg0, FragmentTransaction arg1) { }
@Override
public void onTabSelected(ActionBar.Tab arg0, FragmentTransaction arg1) {
if (mFragment.isAdded())
arg1.show(mFragment);
else
arg1.add(R.id.fragment_content, mFragment, null);
mFragment.actionBarTab = arg0;
}
@Override
public void onTabUnselected(ActionBar.Tab arg0, FragmentTransaction arg1) {
arg1.hide(mFragment);
}
}
}
Java Source Code List jp.ne.hatena.d.shogo0809.widget.SortableListView.java net.azyobuzi.azyotter.saostar.ActivityUtil.java net.azyobuzi.azyotter.saostar.ContextAccess.java net.azyobuzi.azyotter.saostar.NotificationCenter.java net.azyobuzi.azyotter.saostar.SaostarApplication.java net.azyobuzi.azyotter.saostar.StringUtil.java net.azyobuzi.azyotter.saostar.Twitter4JFactories.java net.azyobuzi.azyotter.saostar.TwitterUriGenerator.java net.azyobuzi.azyotter.saostar.activities.AccountPreferenceActivity.java net.azyobuzi.azyotter.saostar.activities.AccountPreferenceFragment.java net.azyobuzi.azyotter.saostar.activities.AccountsActivity.java net.azyobuzi.azyotter.saostar.activities.AccountsFragment.java net.azyobuzi.azyotter.saostar.activities.ExpandLinkActivity.java net.azyobuzi.azyotter.saostar.activities.LoginActivity.java net.azyobuzi.azyotter.saostar.activities.MainActivity.java net.azyobuzi.azyotter.saostar.activities.RetryActivity.java net.azyobuzi.azyotter.saostar.activities.SettingActivity.java net.azyobuzi.azyotter.saostar.activities.SettingFragment.java net.azyobuzi.azyotter.saostar.activities.TabFilterSettingFragment.java net.azyobuzi.azyotter.saostar.activities.TabGeneralSettingFragment.java net.azyobuzi.azyotter.saostar.activities.TabPreferenceActivity.java net.azyobuzi.azyotter.saostar.activities.TabsActivity.java net.azyobuzi.azyotter.saostar.activities.TabsFragment.java net.azyobuzi.azyotter.saostar.activities.TimelineTabFragment.java net.azyobuzi.azyotter.saostar.activities.TweetDetailActivity.java net.azyobuzi.azyotter.saostar.activities.TwitterUriHookActivity.java net.azyobuzi.azyotter.saostar.activities.UpdateStatusActivity.java net.azyobuzi.azyotter.saostar.configuration.Account.java net.azyobuzi.azyotter.saostar.configuration.Accounts.java net.azyobuzi.azyotter.saostar.configuration.Command.java net.azyobuzi.azyotter.saostar.configuration.Setting.java net.azyobuzi.azyotter.saostar.configuration.Tab.java net.azyobuzi.azyotter.saostar.configuration.Tabs.java net.azyobuzi.azyotter.saostar.d_aqa.Constant.java net.azyobuzi.azyotter.saostar.d_aqa.FunctionFactory.java net.azyobuzi.azyotter.saostar.d_aqa.Function.java net.azyobuzi.azyotter.saostar.d_aqa.Invokable.java net.azyobuzi.azyotter.saostar.d_aqa.OperatorFactory.java net.azyobuzi.azyotter.saostar.d_aqa.Operator.java net.azyobuzi.azyotter.saostar.d_aqa.PropertyFactory.java net.azyobuzi.azyotter.saostar.d_aqa.Property.java net.azyobuzi.azyotter.saostar.d_aqa.Reader.java net.azyobuzi.azyotter.saostar.d_aqa.operators.EqualityOperator.java net.azyobuzi.azyotter.saostar.d_aqa.operators.GreaterThanOperator.java net.azyobuzi.azyotter.saostar.d_aqa.operators.GreaterThanOrEqualOperator.java net.azyobuzi.azyotter.saostar.d_aqa.operators.InequalityOperator.java net.azyobuzi.azyotter.saostar.d_aqa.operators.LessThanOperator.java net.azyobuzi.azyotter.saostar.d_aqa.operators.LessThanOrEqualOperator.java net.azyobuzi.azyotter.saostar.d_aqa.properties.CreatedAtProperty.java net.azyobuzi.azyotter.saostar.d_aqa.properties.FromCreatedAtProperty.java net.azyobuzi.azyotter.saostar.d_aqa.properties.FromIdProperty.java net.azyobuzi.azyotter.saostar.d_aqa.properties.FromNameProperty.java net.azyobuzi.azyotter.saostar.d_aqa.properties.FromProtectedProperty.java net.azyobuzi.azyotter.saostar.d_aqa.properties.FromScreenNameProperty.java net.azyobuzi.azyotter.saostar.d_aqa.properties.FromVerifiedProperty.java net.azyobuzi.azyotter.saostar.d_aqa.properties.IdProperty.java net.azyobuzi.azyotter.saostar.d_aqa.properties.InReplyToProperty.java net.azyobuzi.azyotter.saostar.d_aqa.properties.IsHomeTweetProperty.java net.azyobuzi.azyotter.saostar.d_aqa.properties.OriginalTextProperty.java net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedCreatedAtProperty.java net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedIdProperty.java net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedProperty.java net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedSourceProperty.java net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedUserCreatedAtProperty.java net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedUserIdProperty.java net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedUserNameProperty.java net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedUserScreenNameProperty.java net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedUserVerifiedProperty.java net.azyobuzi.azyotter.saostar.d_aqa.properties.SourceProperty.java net.azyobuzi.azyotter.saostar.d_aqa.properties.TextProperty.java net.azyobuzi.azyotter.saostar.linq.Enumerable.java net.azyobuzi.azyotter.saostar.linq.Enumerator.java net.azyobuzi.azyotter.saostar.services.FavoriteService.java net.azyobuzi.azyotter.saostar.services.RetweetService.java net.azyobuzi.azyotter.saostar.services.TimelineReceiveService.java net.azyobuzi.azyotter.saostar.services.UpdateStatusService.java net.azyobuzi.azyotter.saostar.system.Action1.java net.azyobuzi.azyotter.saostar.system.Action2.java net.azyobuzi.azyotter.saostar.system.Action3.java net.azyobuzi.azyotter.saostar.system.Action.java net.azyobuzi.azyotter.saostar.system.Func1.java net.azyobuzi.azyotter.saostar.system.Func2.java net.azyobuzi.azyotter.saostar.system.Func.java net.azyobuzi.azyotter.saostar.timeline_data.TimelineItemCollection.java net.azyobuzi.azyotter.saostar.timeline_data.TimelineItemId.java net.azyobuzi.azyotter.saostar.timeline_data.TimelineItem.java net.azyobuzi.azyotter.saostar.timeline_data.TweetEntities.java net.azyobuzi.azyotter.saostar.timeline_data.UserCollection.java net.azyobuzi.azyotter.saostar.timeline_data.UserInfo.java net.azyobuzi.azyotter.saostar.widget.AccountSelector.java net.azyobuzi.azyotter.saostar.widget.CustomizedUrlImageView.java