Android Open Source - 101AndroidApps Thumbs Up Activity






From Project

Back to project page 101AndroidApps.

License

The source code is released under:

Licenced under the Creative Commons Attribution 4.0 licence. For full text see http://creativecommons.org/licenses/by/4.0/

If you think the Android project 101AndroidApps 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 com.hulzenga.ioi.android.app_009;
/*from   www. j  a  v a2 s . com*/
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import com.hulzenga.ioi.android.AppActivity;
import com.hulzenga.ioi.android.R;

/**
 * Created by jouke on 20-4-14.
 */
public class ThumbsUpActivity extends AppActivity {

  private static final String TAG = "ThumbsUpActivity";

  private ImageButton     mThumbsUpButton;
  private TextView        mServerStatusTextView;
  private ThumbsUpService mThumbsUpService;
  private ServiceConnection mServiceConnection = new ServiceConnection() {

    @Override
    public void onServiceConnected(ComponentName name, IBinder service) {
      ThumbsUpService.ThumbsUpBinder binder = (ThumbsUpService.ThumbsUpBinder) service;
      mThumbsUpService = binder.getService();
      setBound(true);

      if (mThumbsUpService.isServerRunning()) {
        setServerRunning(true);
      }
    }

    @Override
    public void onServiceDisconnected(ComponentName name) {
      setBound(false);
    }
  };
  private boolean mBound;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.app_009_activity_thumbs_up);
    mThumbsUpButton = (ImageButton) findViewById(R.id.app_009_thumbsUpButton);
    mServerStatusTextView = (TextView) findViewById(R.id.app_009_serverStatusTextView);
    mServerStatusTextView.setMovementMethod(LinkMovementMethod.getInstance());

    setBound(false);
    setServerRunning(false);

    mThumbsUpButton.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {

        //mBound should be true if button is enabled, but it can't hurt to check
        if (mBound) {
          if (!mThumbsUpService.isServerRunning()) {
            if (mThumbsUpService.startServer()) {
              setServerRunning(true);
            } else {
              Toast.makeText(ThumbsUpActivity.this, R.string.app_009_server_start_failure, Toast.LENGTH_SHORT).show();
            }
          } else {

            mThumbsUpService.stopServer();
            setServerRunning(false);
          }
        } else {
          Log.w(TAG, "ThumbsUpButton clicked but the service is not bound !");
        }
      }
    });
  }

  private void setBound(boolean bound) {
    if (bound) {
      mBound = true;
      mThumbsUpButton.setEnabled(true);
    } else {
      mBound = false;
      mThumbsUpButton.setEnabled(false);
    }
  }

  private void setServerRunning(boolean running) {
    if (running) {
      mServerStatusTextView.setText(Html.fromHtml(getResources().getString(R.string.app_009_server_running_message)
          + " <a href=\"http://"+mThumbsUpService.getServerAddress()+"\">"+mThumbsUpService.getServerAddress()+"</a>"));
      mThumbsUpButton.setImageDrawable(getResources().getDrawable(R.drawable.app_009_thumbs_up));
    } else {
      mServerStatusTextView.setText(R.string.app_009_start_server_instruction);
      mThumbsUpButton.setImageDrawable(getResources().getDrawable(R.drawable.app_009_thumbs_down));
    }
  }

  @Override
  protected void onStart() {
    super.onStart();

    Intent intent = new Intent(this, ThumbsUpService.class);
    startService(intent);
    bindService(intent, mServiceConnection, Context.BIND_ABOVE_CLIENT);
  }

  @Override
  protected void onStop() {
    super.onStop();

    unbindService(mServiceConnection);

    if (mThumbsUpService != null && !mThumbsUpService.isServerRunning()) {
      Intent intent = new Intent(this, ThumbsUpService.class);
      stopService(intent);
    }

  }
}




Java Source Code List

com.hulzenga.ioi.android.AppActivity.java
com.hulzenga.ioi.android.AppDetailsDialog.java
com.hulzenga.ioi.android.App.java
com.hulzenga.ioi.android.TableOfContentsActivity.java
com.hulzenga.ioi.android.app_001.HelloWorldActivity.java
com.hulzenga.ioi.android.app_002.Ball.java
com.hulzenga.ioi.android.app_002.BouncyBallsActivity.java
com.hulzenga.ioi.android.app_002.BouncyBallsView.java
com.hulzenga.ioi.android.app_003.MonsterDatabaseActivity.java
com.hulzenga.ioi.android.app_003.MonsterEditDialog.java
com.hulzenga.ioi.android.app_003.MonsterGenerator.java
com.hulzenga.ioi.android.app_003.MonsterListAdapter.java
com.hulzenga.ioi.android.app_003.database.MonsterContract.java
com.hulzenga.ioi.android.app_003.database.MonsterDatabaseHelper.java
com.hulzenga.ioi.android.app_003.database.MonsterProvider.java
com.hulzenga.ioi.android.app_004.BouncyBall3dActivity.java
com.hulzenga.ioi.android.app_004.BouncyBall3dGLSurfaceView.java
com.hulzenga.ioi.android.app_004.BouncyBall3dRenderer.java
com.hulzenga.ioi.android.app_004.BouncyBallGame.java
com.hulzenga.ioi.android.app_005.ElementActivity.java
com.hulzenga.ioi.android.app_005.ElementAdapter.java
com.hulzenga.ioi.android.app_005.ElementAnimator.java
com.hulzenga.ioi.android.app_005.ElementSnakeView.java
com.hulzenga.ioi.android.app_005.ElementView.java
com.hulzenga.ioi.android.app_005.Element.java
com.hulzenga.ioi.android.app_006.EmptyFragment.java
com.hulzenga.ioi.android.app_006.ExposureFragment.java
com.hulzenga.ioi.android.app_006.SettingChangeListener.java
com.hulzenga.ioi.android.app_006.SettingIconFragment.java
com.hulzenga.ioi.android.app_006.SettingMenuFragment.java
com.hulzenga.ioi.android.app_006.SettingMenuLvl2Fragment.java
com.hulzenga.ioi.android.app_006.Setting.java
com.hulzenga.ioi.android.app_006.SimpleCameraActivity.java
com.hulzenga.ioi.android.app_006.SimpleCameraPreview.java
com.hulzenga.ioi.android.app_007.ButtonsFragment.java
com.hulzenga.ioi.android.app_007.HighScores.java
com.hulzenga.ioi.android.app_007.LinksFragment.java
com.hulzenga.ioi.android.app_007.Menu.java
com.hulzenga.ioi.android.app_007.Review.java
com.hulzenga.ioi.android.app_007.Score.java
com.hulzenga.ioi.android.app_007.StatusFragment.java
com.hulzenga.ioi.android.app_007.WikiGameActivity.java
com.hulzenga.ioi.android.app_007.Wiki.java
com.hulzenga.ioi.android.app_008.OverheidActivity.java
com.hulzenga.ioi.android.app_008.OverheidFeedAdapter.java
com.hulzenga.ioi.android.app_008.OverheidFeedFragment.java
com.hulzenga.ioi.android.app_008.OverheidFeedItem.java
com.hulzenga.ioi.android.app_008.OverheidFeed.java
com.hulzenga.ioi.android.app_008.OverheidPagerAdapter.java
com.hulzenga.ioi.android.app_009.ThumbsUpActivity.java
com.hulzenga.ioi.android.app_009.ThumbsUpServer.java
com.hulzenga.ioi.android.app_009.ThumbsUpService.java
com.hulzenga.ioi.android.app_010.CompassActivity.java
com.hulzenga.ioi.android.app_010.CompassDetailsView.java
com.hulzenga.ioi.android.app_010.CompassView.java
com.hulzenga.ioi.android.util.Constrain.java
com.hulzenga.ioi.android.util.DeveloperTools.java
com.hulzenga.ioi.android.util.FileManager.java
com.hulzenga.ioi.android.util.ScreenMetrics.java
com.hulzenga.ioi.android.util.open_gl.ColorFunctionFactory.java
com.hulzenga.ioi.android.util.open_gl.ColorFunction.java
com.hulzenga.ioi.android.util.open_gl.ShaderTools.java
com.hulzenga.ioi.android.util.open_gl.engine.NodeController.java
com.hulzenga.ioi.android.util.open_gl.engine.SceneGraph.java
com.hulzenga.ioi.android.util.open_gl.engine.SceneNode.java
com.hulzenga.ioi.android.util.open_gl.geometry.Box.java
com.hulzenga.ioi.android.util.open_gl.geometry.Cylinder.java
com.hulzenga.ioi.android.util.open_gl.geometry.Geometry.java
com.hulzenga.ioi.android.util.open_gl.geometry.Grid.java
com.hulzenga.ioi.android.util.open_gl.geometry.Sphere.java
com.hulzenga.ioi.android.util.open_gl.geometry.Transform.java
com.hulzenga.ioi.android.util.open_gl.vector.Vec3.java
com.hulzenga.ioi.android.util.open_gl.vector.Vec4.java
fi.iki.elonen.NanoHTTPD.java