cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              //this is Java Code, bitches!

package com.example.annikawestphaling.staedte;

import android.Manifest;
import android.app.ActionBar;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.content.pm.PackageManager;
import android.location.Location;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.widget.Toast;


import com.example.annikawestphaling.staedte.API_classes.ChiliLocationsAPI;
import com.example.annikawestphaling.staedte.Fragments.TabFragment1;
import com.example.annikawestphaling.staedte.Fragments.TabFragment3;
import com.example.annikawestphaling.staedte.Listener.LocationDataAvailableListener;
import com.example.annikawestphaling.staedte.Listener.LogOutButtonPushedListener;
import com.example.annikawestphaling.staedte.Listener.LogOutButtonPushedListenerMain;
import com.example.annikawestphaling.staedte.Listener.OnBackButtonClickedListener;
import com.example.annikawestphaling.staedte.Listener.RegisterForLocationUpdatesListener;
import com.example.annikawestphaling.staedte.Listener.RegisterForStackManagerListener;
import com.example.annikawestphaling.staedte.Listener.RegisterForUserLoggedOutListener;
import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationServices;

import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.logging.HttpLoggingInterceptor;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import retrofit.Call;
import retrofit.Callback;
import retrofit.GsonConverterFactory;
import retrofit.Response;
import retrofit.Retrofit;


public class MainActivity extends AppCompatActivity implements
        GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener,
        RegisterForLocationUpdatesListener,
        RegisterForUserLoggedOutListener,
        LogOutButtonPushedListenerMain,
        RegisterForStackManagerListener {


    GoogleApiClient mGoogleApiClient;
    Location mLastLocation;
    double mLatitude;
    double mLongitude;
    ArrayList<LocationDataAvailableListener> locationDataAvailableListeners = new ArrayList<>();
    ArrayList<LogOutButtonPushedListener> logOutButtonPushedListeners = new ArrayList<>();
    ArrayList<OnBackButtonClickedListener> onBackButtonClickedListeners = new ArrayList<>();
    private com.example.annikawestphaling.staedte.API_classes.Location[] locationsList;
    OnBackButtonClickedListener fragmentTab1;
    OnBackButtonClickedListener fragmentTab2;
    OnBackButtonClickedListener fragmentTab3;
    ViewPager viewPager;
    int firstFragmentSet;
    TabLayout tabLayout;


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


        setContentView(R.layout.activity_main);

        if (mGoogleApiClient == null) {
            mGoogleApiClient = new GoogleApiClient.Builder(this)
                    .addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this)
                    .addApi(LocationServices.API)
                    .addApi(AppIndex.API).build();
        }

        HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
        logging.setLevel(HttpLoggingInterceptor.Level.BODY);
        OkHttpClient httpClient = new OkHttpClient();
        httpClient.interceptors().add(logging);

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(BLA)
                .addConverterFactory(GsonConverterFactory.create())
                .client(httpClient)
                .build();
        ChiliLocationsAPI chiliLocationsAPI = retrofit.create(ChiliLocationsAPI.class);
        Call<LocationsList> call = chiliLocationsAPI.loadLocations();
        call.enqueue(new Callback<LocationsList>() {
            @Override
            public void onResponse(Response<LocationsList> response, Retrofit retrofit) {
                List mArrayList = (List) response.body().result;
                locationsList = (com.example.annikawestphaling.staedte.API_classes.Location[]) mArrayList.toArray(new com.example.annikawestphaling.staedte.API_classes.Location[mArrayList.size()]);
                Log.d("onResponse", locationsList[3].getName());

                for (LocationDataAvailableListener listener : locationDataAvailableListeners) {
                    if (listener != null)
                        listener.locationsAvailable(locationsList, mLatitude, mLongitude);
                }
            }

            @Override
            public void onFailure(Throwable t) {
                Log.d("onFailure", "das Problem ist" + t.getLocalizedMessage());
                Toast.makeText(getBaseContext(), t.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
            }
        });

        tabLayout = (TabLayout) findViewById(R.id.tab_layout);
        tabLayout.addTab(tabLayout.newTab().setText("Tab 1"));
        tabLayout.addTab(tabLayout.newTab().setText("Tab 2"));
        tabLayout.addTab(tabLayout.newTab().setText("Tab 3"));
        tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
        firstFragmentSet = 0;


        viewPager = (NonSwipeableViewPager) findViewById(R.id.pager);
        PageAdapter adapter = new PageAdapter
                (getSupportFragmentManager(), tabLayout.getTabCount());
        viewPager.setAdapter(adapter);
        viewPager.setOffscreenPageLimit(2);
        viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
        tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                Log.d("onTabSelected", "position" + tab.getPosition());
                viewPager.setCurrentItem(tab.getPosition());
                if (tab.getPosition() == 2) {
                    SharedPreferences isUserLoggedIn = getSharedPreferences("loggedInUser", MODE_PRIVATE);
                    String username = isUserLoggedIn.getString("loggedInUserName", null);
                    if (username == null) ((TabFragment3) fragmentTab3).inflateLogInScreen();
                    else {
                        ((TabFragment3) fragmentTab3).onLogInButtonPushed(0);
                    }
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {
            }
        });


    }


    protected void onStart() {

        super.onStart();

        SharedPreferences isUserLoggedIn = getSharedPreferences("loggedInUser", MODE_PRIVATE);
        String username = isUserLoggedIn.getString("loggedInUserName", null);
        Log.d("Tab Fragment 3", username + " is logged in");

        mGoogleApiClient.connect();
        Action viewAction = Action.newAction(
                Action.TYPE_VIEW,
                "Main Page", 
                Uri.parse("http://host/path"),
                Uri.parse("android-app://com.example.annikawestphaling.staedte/http/host/path")
        );
        AppIndex.AppIndexApi.start(mGoogleApiClient, viewAction);
    }


    protected void onStop() {
        mGoogleApiClient.disconnect();
        super.onStop();
        Action viewAction = Action.newAction(
                Action.TYPE_VIEW, 
                "Main Page",
                Uri.parse("http://host/path"),
                Uri.parse("android-app://com.example.annikawestphaling.staedte/http/host/path")
        );
        AppIndex.AppIndexApi.end(mGoogleApiClient, viewAction);
    }

    @Override
    public void onConnected(Bundle connectionHint) {
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
        }
        if (mLastLocation != null) {
            mLatitude = mLastLocation.getLatitude();
            mLongitude = mLastLocation.getLongitude();
        }
        Log.d("onConnected", String.valueOf(mLatitude) + " latitude " + String.valueOf(mLongitude) + " longitude ");
    }


    @Override
    public void onConnectionSuspended(int i) {
    }

    @Override
    public void onConnectionFailed(ConnectionResult connectionResult) {

    }

    public com.example.annikawestphaling.staedte.API_classes.Location[] getLocationsList() {
        return locationsList;
    }

    @Override
    public void onBackPressed() {
        //super.onBackPressed();
        int selectedTabPosition = tabLayout.getSelectedTabPosition();
        switch (selectedTabPosition) {
            case 0:
                fragmentTab1.onBackButtonClicked();
                break;
            case 1:
                fragmentTab2.onBackButtonClicked();
                break;
            case 2:
                fragmentTab3.onBackButtonClicked();
                break;
            default:
                break;
        }
    }


    public void addLocationDataAvailableListener(LocationDataAvailableListener listener) {
        locationDataAvailableListeners.add(listener);
    }

    public void removeLocationDataAvailableListener(LocationDataAvailableListener listener) {
        locationDataAvailableListeners.remove(listener);
    }

    @Override
    public void addUserLoggedOutListener(LogOutButtonPushedListener listener) {
        logOutButtonPushedListeners.add(listener);
    }

    @Override
    public void removeUserLoggedOutListener(LogOutButtonPushedListener listener) {
        logOutButtonPushedListeners.remove(listener);
    }

    @Override
    public void addFragmentToStackManager(OnBackButtonClickedListener listener) {
        onBackButtonClickedListeners.add(listener);
    }

    @Override
    public void removeFragmentFromStackManager(OnBackButtonClickedListener listener) {
        onBackButtonClickedListeners.remove(listener);
    }

    @Override
    public void updateTab1Fragment(OnBackButtonClickedListener listener) {
        fragmentTab1 = listener;
    }

    @Override
    public void updateTab2Fragment(OnBackButtonClickedListener listener) {
        fragmentTab2 = listener;
    }

    @Override
    public void updateTab3Fragment(OnBackButtonClickedListener listener) {
        fragmentTab3 = listener;
    }

    @Override
    public void returnToTab1() {
        viewPager.setCurrentItem(0);
        ((TabFragment1) fragmentTab1).showMapsAndListThenClose();

    }

    @Override
    public void forAllLogOutButtonPushedListenersDo() {
        viewPager.setCurrentItem(0);
        for (LogOutButtonPushedListener logOutButtonPushedListener : logOutButtonPushedListeners) {
            logOutButtonPushedListener.logOutButtonPushedListenerMethod();
        }
    }
}
            
          
!
999px
Loading ..................

Console