Android Open Source - AndroidWifiServer Gate Activity






From Project

Back to project page AndroidWifiServer.

License

The source code is released under:

Apache License

If you think the Android project AndroidWifiServer 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 jp.maju.wifiserver;
//from   w  ww  .  j  a  v  a 2s.co m
import jp.maju.wifiserver.client.ClientActivity;
import jp.maju.wifiserver.server.InitServerActivity;
import jp.maju.wifiserver.server.ServerActivity;
import jp.maju.wifiserver.twitter.ProxyDialogFragment;
import jp.maju.wifiserver.twitter.ProxyWrapper;
import jp.maju.wifiserver.twitter.TwitterOAuthActivity;
import jp.maju.wifiserver.twitter.TwitterUtils;
import jp.maju.wifiserver.twitter.ProxyDialogFragment.OnSetProxyListener;
import jp.maju.wifiserver.util.CommonUtil;
import jp.maju.wifiserver.util.PreferenceUtil;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;

/*
 * Copyright {2014} {Matsuda Jumpei}
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
public class GateActivity extends ActionBarActivity implements OnClickListener, OnSetProxyListener {
    private static final String TAG = GateActivity.class.getSimpleName();
    private static final String KEY_FIRST_VISIT = "keyIsFirstVisiting";
    
    private String curSSID;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        int side = PreferenceUtil.getDefaultSide(getApplication());

        if (side == 1) {
            startActivity(new Intent(this, ServerActivity.class));
            finish();
        } else if (side == 2) {
            String ssid = CommonUtil.getCurrentSSID(getApplicationContext());
            SocketInfo si = new SocketInfo(ssid);
            si.setHost(PreferenceUtil.getServerHostOnClient(getApplication(), ssid));
            si.setPort(PreferenceUtil.getServerPortOnClient(getApplication(), ssid));
            startActivity(new Intent(this, ClientActivity.class).putExtra(ClientActivity.KEY_SOCKET_INFO, si));
            finish();
        } else {
            setContentView(R.layout.activity_gate);
            
            findViewById(R.id.btn_gate_client).setOnClickListener(this);
            findViewById(R.id.btn_gate_server).setOnClickListener(this);
            
            curSSID = CommonUtil.getCurrentSSID(getApplicationContext());
        }
    }
    
    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        
        if (curSSID != null) {
            boolean isFirstVisiting = getSharedPreferences(TAG, Context.MODE_PRIVATE).getBoolean(KEY_FIRST_VISIT + curSSID, true);
        
            if (hasFocus && isFirstVisiting) {
                ProxyDialogFragment.show(getSupportFragmentManager());
            }
        }
    }

    @Override
    public void onClick(View v) {
        switch(v.getId()) {
            case R.id.btn_gate_client:
                startActivity(new Intent(this, TwitterOAuthActivity.class).putExtra(TwitterOAuthActivity.KEY_IS_SERVER, false));
                break;
            case R.id.btn_gate_server:
                startActivity(new Intent(this, InitServerActivity.class));
                break;
        }
        finish();
    }

    @Override
    public void onComplete() {
        getSharedPreferences(TAG, Context.MODE_PRIVATE).edit().putBoolean(KEY_FIRST_VISIT+curSSID, false).commit();
        Toast.makeText(getApplicationContext(), R.string.msg_proxy_accepted, Toast.LENGTH_SHORT).show();
    }
}




Java Source Code List

jp.maju.wifiserver.AsyncExecutionTask.java
jp.maju.wifiserver.CustomWebView.java
jp.maju.wifiserver.DBAdapter.java
jp.maju.wifiserver.GateActivity.java
jp.maju.wifiserver.HTMLBuilder.java
jp.maju.wifiserver.SocketInfo.java
jp.maju.wifiserver.camera.CameraSurfaceView.java
jp.maju.wifiserver.camera.QRReaderActivity.java
jp.maju.wifiserver.client.ClientActivity.java
jp.maju.wifiserver.client.ClientService.java
jp.maju.wifiserver.server.InitServerActivity.java
jp.maju.wifiserver.server.ServerActivity.java
jp.maju.wifiserver.server.ServerService.java
jp.maju.wifiserver.twitter.ProxyDialogFragment.java
jp.maju.wifiserver.twitter.ProxyWrapper.java
jp.maju.wifiserver.twitter.TweetTask.java
jp.maju.wifiserver.twitter.TwitterOAuthActivity.java
jp.maju.wifiserver.twitter.TwitterUtils.java
jp.maju.wifiserver.util.CommonUtil.java
jp.maju.wifiserver.util.Logger.java
jp.maju.wifiserver.util.PreferenceUtil.java