Android Open Source - SpunkyCharts Init Activity






From Project

Back to project page SpunkyCharts.

License

The source code is released under:

GNU General Public License

If you think the Android project SpunkyCharts 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.jogden.spunkycharts;
/*from   w w  w . j a v a 2 s . com*/
/* 
Copyright (C) 2014 Jonathon Ogden     < jeog.dev@gmail.com >


This program 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.

This program 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 this program.  If not, see http://www.gnu.org/licenses.
*/

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class InitActivity extends Activity 
{        
    private Activity _this = this;    
    private View _openingView;
    @Override
    public void onCreate(Bundle savedInstanceState)
    { 
        this.getActionBar().hide();
        super.onCreate(savedInstanceState);    
        /* be sure to pass our contex before we open main view */
        InitButtonClicks.setCaller(this);
         _openingView = new OpeningView(this);        
        setContentView(_openingView);       
    }    
    
    @Override
    public void onStart()
    {
        super.onStart();
        _openingView.invalidate();
        checkConnection();      
        MainApplication.readyForData = true;        
        MainApplication.connectToDataService();                   
    }
    @Override
    public void onActivityResult(int request, int result, Intent data)
    {
        super.onActivityResult(request, result, data);    
        if( request == MainApplication.WIRELESS_SETTINGS_REQ){
            if( result == Activity.RESULT_OK )        
                this.checkConnection();        
            else {
                //TODO: what do we want to do here?
                return;
            }
        }
    }        
    // deal with the dialog losing focus w/o a selection
    public void checkConnection() 
    {       
        AlertDialog.Builder adb;    
        ConnectivityManager cm = 
            (ConnectivityManager)getSystemService(
                Context.CONNECTIVITY_SERVICE
                );  
        NetworkInfo nwI = cm.getActiveNetworkInfo(); 
        if ( ( nwI == null) || !nwI.isConnectedOrConnecting()) 
        {            
            adb = new AlertDialog.Builder(this);
            adb.setTitle("You are not connected to the internet");
            adb.setItems(
                new CharSequence[]
                    { 
                    "Take me to Network Settings", 
                    "Exit"
                    },    
                new DialogInterface.OnClickListener(){                        
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        switch(which){
                        case 0: // goto network settings        
                            _this.startActivityForResult(
                                new Intent(Settings.ACTION_WIRELESS_SETTINGS), 
                                MainApplication.WIRELESS_SETTINGS_REQ
                                );                            
                            MainApplication.readyForData = false;                            
                            break;                    
                        default: 
                            _this.finish();
                        }                        
                    }
                });
            adb.setCancelable(false);    
            adb.show();        
        } 
        else if ( nwI.getType() != ConnectivityManager.TYPE_WIFI) 
        {            
            adb = new AlertDialog.Builder(this);             
            adb.setTitle(
                "You are not connected via Wi-Fi (Data Charges May Apply!)"
                );
            adb.setItems(
                new CharSequence[]
                    { 
                    "Take me to Network Settings", 
                    "Proceed Without Wi-Fi", 
                    "Exit"
                    },
                new DialogInterface.OnClickListener(){                        
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        switch(which){
                        case 0:     
                            _this.startActivityForResult(
                                new Intent(Settings.ACTION_WIRELESS_SETTINGS),
                                MainApplication.WIRELESS_SETTINGS_REQ
                                );                            
                            MainApplication.readyForData = false;                            
                            break;
                        case 1:     
                            MainApplication.readyForData = true;    
                            break;                
                        default: 
                            _this.finish();
                        }                        
                    }
                });
            adb.setCancelable(false);    
            adb.show();        
        }    
    }
    
    public static class InitButtonClicks
    {            
        static private Context caller;
        static public void setCaller(Context c)
        {
            caller = c;
        }
        static private Context getAndCheckCaller()
        {
            if(caller == null)
                throw new NullPointerException(
                    "InitButtonClicks.caller is null, can not create intent"
                    );            
            return caller;
        }
        static class Start implements Button.OnClickListener{            
            @Override
            public void onClick(View arg0) {
                if( MainApplication.readyForData ){    
                    Context c = getAndCheckCaller();
                    c.startActivity( new Intent(c, DockingPanelActivity.class )    );
                }
                else 
                    throw new 
                        MainApplication.AppNotReadyForDataException(
                            "readyForData == false in Start.onClick()"
                            );    
            }        
        }
        static class About implements Button.OnClickListener    {
            @Override
            public void onClick(View arg0) {            
                    Toast.makeText( caller, "N/A!",    Toast.LENGTH_LONG).show();
            }                    
        }
        static class Settings implements Button.OnClickListener{
            @Override
            public void onClick(View arg0) {            
                Context c = getAndCheckCaller();
                c.startActivity( new Intent(c, ApplicationPreferences.class) );
            }    
        }
    }

    
}




Java Source Code List

com.jogden.spunkycharts.ApplicationPreferences.java
com.jogden.spunkycharts.BaseChartFragmentA.java
com.jogden.spunkycharts.ChartPanelSurfaceView.java
com.jogden.spunkycharts.DockingPanelActivity.java
com.jogden.spunkycharts.GlobalChartPreferences.java
com.jogden.spunkycharts.InitActivity.java
com.jogden.spunkycharts.MainApplication.java
com.jogden.spunkycharts.OpeningView.java
com.jogden.spunkycharts.animations.BaseAnimationA.java
com.jogden.spunkycharts.animations.BaseEntExAnimationA.java
com.jogden.spunkycharts.animations.BaseSelectAnimationA.java
com.jogden.spunkycharts.animations.HorizontalBulgeAnimation.java
com.jogden.spunkycharts.animations.HorizontalShakeAnimation.java
com.jogden.spunkycharts.animations.VerticalBulgeAnimation.java
com.jogden.spunkycharts.animations.VerticalShakeAnimation.java
com.jogden.spunkycharts.animations.WiggleAnimation.java
com.jogden.spunkycharts.data.DataClientLocalDebug.java
com.jogden.spunkycharts.data.DataContentService.java
com.jogden.spunkycharts.misc.BorderOverlay.java
com.jogden.spunkycharts.misc.ColorPaletteDialog.java
com.jogden.spunkycharts.misc.HideHorizontalLeftOverflowWrapper.java
com.jogden.spunkycharts.misc.OHLC.java
com.jogden.spunkycharts.misc.Pair.java
com.jogden.spunkycharts.misc.TextInput.java
com.jogden.spunkycharts.misc.Triple.java
com.jogden.spunkycharts.pricebyvolumechart.PriceByVolumeChartFragmentAdapter.java
com.jogden.spunkycharts.pricebyvolumechart.PriceByVolumeChartFragment.java
com.jogden.spunkycharts.pricebyvolumechart.PriceByVolumeChartPanel.java
com.jogden.spunkycharts.pricebyvolumechart.PriceByVolumeChartPreferences.java
com.jogden.spunkycharts.pricebyvolumechart.draw.DrawSemanticsA.java
com.jogden.spunkycharts.pricebyvolumechart.draw.DrawSemantics_SILO.java
com.jogden.spunkycharts.traditionalchart.InnerXAxis.java
com.jogden.spunkycharts.traditionalchart.TraditionalChartFragmentAdapter.java
com.jogden.spunkycharts.traditionalchart.TraditionalChartFragment.java
com.jogden.spunkycharts.traditionalchart.TraditionalChartPanel.java
com.jogden.spunkycharts.traditionalchart.TraditionalChartPreferences.java
com.jogden.spunkycharts.traditionalchart.XAxisTimeLabel.java
com.jogden.spunkycharts.traditionalchart.YAxisPriceLabel.java
com.jogden.spunkycharts.traditionalchart.draw.DrawSemanticsA_C.java
com.jogden.spunkycharts.traditionalchart.draw.DrawSemanticsA.java
com.jogden.spunkycharts.traditionalchart.draw.DrawSemantics_CANDLE.java
com.jogden.spunkycharts.traditionalchart.draw.DrawSemantics_LINE.java
com.jogden.spunkycharts.traditionalchart.draw.DrawSemantics_OC.java
com.jogden.spunkycharts.traditionalchart.draw.DrawSemantics_OHLC.java
com.jogden.spunkycharts.traditionalchart.draw.DrawSemantics_POINT.java
com.jogden.spunkycharts.traditionalchart.draw.DrawSemantics_SILO.java