Android Open Source - MyTwitter-Android Settings Activity






From Project

Back to project page MyTwitter-Android.

License

The source code is released under:

Apache License

If you think the Android project MyTwitter-Android 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 org.fukata.android.mytw;
//from   ww  w.j a  v  a2s.com
import org.fukata.android.mytw.twitter.Twitter;
import org.fukata.android.mytw.twitter.rs.User;
import org.fukata.android.mytw.util.SettingUtil;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

public class SettingsActivity extends Activity implements OnClickListener {
  EditText apiServerUrl;
  Spinner fontSizes;
  Spinner autoIntervals;
  Spinner timelineCounts;
  CheckBox backgroundProcess;
  CheckBox notification;
  TextView accountName;
  TextView accountId;
  Button updateUser;

  Twitter twitter;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.settings);
    SettingUtil.init(this);
    twitter = new Twitter();
    
    accountName = (TextView) findViewById(R.id.account_name);
    accountId = (TextView) findViewById(R.id.account_id);
    updateUser = (Button) findViewById(R.id.update_user);
    apiServerUrl = (EditText) findViewById(R.id.api_server_url);
    fontSizes = (Spinner) findViewById(R.id.font_size);
    autoIntervals = (Spinner) findViewById(R.id.auto_interval);
    timelineCounts = (Spinner) findViewById(R.id.timeline_count);
    backgroundProcess = (CheckBox) findViewById(R.id.background_process);
    notification = (CheckBox) findViewById(R.id.notification);

    backgroundProcess.setOnClickListener(this);
    updateUser.setOnClickListener(this);
    
    initFields();
  }
  
  private void initFields() {
    accountName.setText(SettingUtil.getAccountName());
    accountId.setText(SettingUtil.getAccountId());
    apiServerUrl.setText(SettingUtil.getApiServerUrl());
    fontSizes.setSelection(SettingUtil.getFontSizeIndex());
    autoIntervals.setSelection(SettingUtil.getAutoIntervalIndex());
    timelineCounts.setSelection(SettingUtil.getTimelineCountIndex());
    backgroundProcess.setChecked(SettingUtil.isBackgroundProcessEnabled());
    notification.setChecked(SettingUtil.isNotificationEnabled());
    
    updateFields();
  }
  
  private void updateFields() {
    boolean checked = backgroundProcess.isChecked();
    notification.setEnabled(checked);
  }
  
  @Override
  protected void onPause() {
    super.onPause();
    // api server
    SettingUtil.setApiServerUrl(apiServerUrl.getText().toString());
    // font size
    int size = fontSizes.getSelectedItemPosition();
    SettingUtil.setFontSize(size);
    // auto interval
    int interval = autoIntervals.getSelectedItemPosition();
    SettingUtil.setAutoInterval(interval);
    // timeline count
    int timelineCount = timelineCounts.getSelectedItemPosition();
    SettingUtil.setTimelineCount(timelineCount);
    // background process
    SettingUtil.setBackgroundProcess(backgroundProcess.isChecked());
    // notification
    SettingUtil.setNotification(notification.isChecked());
  }

  @Override
  public void onClick(View v) {
    if (v==backgroundProcess) {
      updateFields();
    } else if (v==updateUser) {
      updateFields();
      updateUser();
    }
  }

  private void updateUser() {
    User user = twitter.getUser();
    if (user == null) {
      return;
    }
    
    accountName.setText(user.getScreenname());
    accountId.setText(user.getId());
    SettingUtil.setAccountName(user.getScreenname());
    SettingUtil.setAccountId(user.getId());
  }
}




Java Source Code List

org.fukata.android.mytw.DirectMessageTimelineAdapter.java
org.fukata.android.mytw.DirectMessageTimelineView.java
org.fukata.android.mytw.HomeTimelineView.java
org.fukata.android.mytw.MentionTimelineView.java
org.fukata.android.mytw.MyTwitterActivity.java
org.fukata.android.mytw.MyTwitterApp.java
org.fukata.android.mytw.SettingsActivity.java
org.fukata.android.mytw.TimelineActivity.java
org.fukata.android.mytw.TimelineAdapter.java
org.fukata.android.mytw.TimelineItem.java
org.fukata.android.mytw.TimelineView.java
org.fukata.android.mytw.UpdateStatusActivity.java
org.fukata.android.mytw.database.MyTwitterDB.java
org.fukata.android.mytw.database.dao.BaseDao.java
org.fukata.android.mytw.database.dao.TweetDao.java
org.fukata.android.mytw.database.dto.TweetDto.java
org.fukata.android.mytw.database.schema.TweetSchema.java
org.fukata.android.mytw.receiver.InstallAnalyticsReceiver.java
org.fukata.android.mytw.twitter.Twitter.java
org.fukata.android.mytw.twitter.rs.Status.java
org.fukata.android.mytw.twitter.rs.User.java
org.fukata.android.mytw.util.PrettyDateUtil.java
org.fukata.android.mytw.util.SettingUtil.java
org.fukata.android.mytw.util.StringMatchUtils.java
org.fukata.android.mytw.util.StringUtils.java