/* * Copyright 2014 Klinker Apps Inc. * * 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. */ package com.klinker.android.launcher.hello_world; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.*; import com.klinker.android.launcher.api.BaseLauncherPage; import com.klinker.android.launcher.api.ResourceHelper; /** * Simple example, Hello World, launcher fragment. * Can be used as a base to create your own and understand the simple parts * of the launcher apis. */ public class LauncherFragment extends BaseLauncherPage { public Context context; private ResourceHelper resHelper; private Utils utils; // root view of the fragment private RelativeLayout rootView; private View background; /** * Creates and instance of this fragment which is then returned to the pager adapter and displayed * @param position the position on the pager of this page * @return an instance of the LauncherFragment to be displayed */ @Override public BaseLauncherPage getFragment(int position) { return new LauncherFragment(); } /** * Creates a View array which will be faded in and out as the page is opened and closed from the main launcher * @return an array of all the views to be faded in and out */ @Override public View[] getBackground() { return new View[] {background}; } @Override public void onAttach(Activity activity) { super.onAttach(activity); context = activity; // initialize a utils object utils = new Utils(activity); // initialize our resource helper so that we can get layouts, drawables, ect. This is required // so that the launcher can get resources from different packages, using R.string.example or // R.drawable.example won't work correctly because it will try to grab the resource that the launcher // holds at that position, not the resource that this package holds. resHelper = new ResourceHelper(activity, Utils.PACKAGE_NAME); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); // inflate our view to be displayed with the helper rootView = (RelativeLayout) resHelper.getLayout("hello_layout"); background = rootView.findViewById(resHelper.getId("background")); // we use this content view to hold all of the actual data. // technichally it isn't necessary, but I use it as a linear layout so that we can put // the nav bar spacer at the bottom. Something that you probably shouldn't forget about. // we do have to deal with transparent bars for the most part here LinearLayout content = (LinearLayout) rootView.findViewById(resHelper.getId("content")); // Add padding at the bottom of the list if the navigation bar is showing and translucent if (utils.isKitKat() && utils.hasNavBar()) { View navBarSpace = new View(context); navBarSpace.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, utils.getNavBarHeight() )); // PLEASE READ: // in this example, I set the background color for it to black, so you can tell where it is. // this isn't necessary. This just goes as a reminder that transparent bars WILL affect the // content of your layout. Your users will not appreciate it if they cannot click // on items because they are behind the system bars. Keep that in mind :) navBarSpace.setBackgroundColor(resHelper.getColor("black")); content.addView(navBarSpace); } return rootView; } }