Mercurial > cgi-bin > hgwebdir.cgi > FriendStream > ASProto
changeset 1:bae640f518e4
Adding auto generated project files, plus Activity code
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/.gitignore Mon Apr 20 17:11:10 2015 +0300 1.3 @@ -0,0 +1,6 @@ 1.4 +.gradle 1.5 +/local.properties 1.6 +/.idea/workspace.xml 1.7 +/.idea/libraries 1.8 +.DS_Store 1.9 +/build
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/app/.gitignore Mon Apr 20 17:11:10 2015 +0300 2.3 @@ -0,0 +1,1 @@ 2.4 +/build
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/app/proguard-rules.pro Mon Apr 20 17:11:10 2015 +0300 3.3 @@ -0,0 +1,17 @@ 3.4 +# Add project specific ProGuard rules here. 3.5 +# By default, the flags in this file are appended to flags specified 3.6 +# in /home/kshalle/Android/Sdk/tools/proguard/proguard-android.txt 3.7 +# You can edit the include path and order by changing the proguardFiles 3.8 +# directive in build.gradle. 3.9 +# 3.10 +# For more details, see 3.11 +# http://developer.android.com/guide/developing/tools/proguard.html 3.12 + 3.13 +# Add any project specific keep options here: 3.14 + 3.15 +# If your project uses WebView with JS, uncomment the following 3.16 +# and specify the fully qualified class name to the JavaScript interface 3.17 +# class: 3.18 +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { 3.19 +# public *; 3.20 +#}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/app/src/androidTest/java/com/example/friendstream/friendstream/ApplicationTest.java Mon Apr 20 17:11:10 2015 +0300 4.3 @@ -0,0 +1,13 @@ 4.4 +package com.example.friendstream.friendstream; 4.5 + 4.6 +import android.app.Application; 4.7 +import android.test.ApplicationTestCase; 4.8 + 4.9 +/** 4.10 + * <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a> 4.11 + */ 4.12 +public class ApplicationTest extends ApplicationTestCase<Application> { 4.13 + public ApplicationTest() { 4.14 + super(Application.class); 4.15 + } 4.16 +} 4.17 \ No newline at end of file
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/app/src/main/AndroidManifest.xml Mon Apr 20 17:11:10 2015 +0300 5.3 @@ -0,0 +1,33 @@ 5.4 +<?xml version="1.0" encoding="utf-8"?> 5.5 +<manifest xmlns:android="http://schemas.android.com/apk/res/android" 5.6 + package="com.example.friendstream.friendstream" > 5.7 + 5.8 + <!--allows music to play in the background, after Activity view switched out --> 5.9 + <uses-permission android:name="android.permission.WAKE_LOCK" /> 5.10 + 5.11 + <!--Generated by Android Studio --> 5.12 + <application 5.13 + android:allowBackup="true" 5.14 + android:icon="@mipmap/ic_launcher" 5.15 + android:label="@string/app_name" 5.16 + android:theme="@style/AppTheme" > 5.17 + <activity 5.18 + android:name=".PickingSongs" 5.19 + android:configChanges="orientation|keyboardHidden|screenSize" 5.20 + android:label="@string/app_name" 5.21 + android:theme="@style/FullscreenTheme" > 5.22 + <intent-filter> 5.23 + <action android:name="android.intent.action.MAIN" /> 5.24 + 5.25 + <category android:name="android.intent.category.LAUNCHER" /> 5.26 + </intent-filter> 5.27 + </activity> 5.28 + 5.29 + <service 5.30 + android:name=".MusicService" 5.31 + android:enabled="true" 5.32 + android:exported="true" > 5.33 + </service> 5.34 + </application> 5.35 + 5.36 +</manifest>
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/app/src/main/java/com/example/friendstream/friendstream/MusicService.java Mon Apr 20 17:11:10 2015 +0300 6.3 @@ -0,0 +1,132 @@ 6.4 +/* 6.5 +Made from tutorial: 6.6 +http://code.tutsplus.com/tutorials/create-a-music-player-on-android-song-playback--mobile-22778 6.7 + */ 6.8 + 6.9 + 6.10 +package com.example.friendstream.friendstream; 6.11 + 6.12 +import android.app.Service; 6.13 +import android.content.ContentUris; 6.14 +import android.content.Intent; 6.15 +import android.media.MediaPlayer; 6.16 +import android.net.Uri; 6.17 +import android.os.IBinder; 6.18 +import java.util.ArrayList; 6.19 + 6.20 +import android.media.AudioManager; 6.21 +import android.os.Binder; 6.22 +import android.os.PowerManager; 6.23 +import android.util.Log; 6.24 + 6.25 +/* 6.26 +Add a Service to the app, which will bind to the song picking activity, and will be what causes 6.27 + the audio to begin playing 6.28 +Make sure the class name matches what is listed in the Manifest. 6.29 + */ 6.30 +public class MusicService extends Service implements 6.31 + MediaPlayer.OnPreparedListener, MediaPlayer.OnErrorListener, 6.32 + MediaPlayer.OnCompletionListener { 6.33 + 6.34 + // Activity will pass in a list of songPlayList, and will play each using the MediaPlayer class 6.35 + private MediaPlayer mediaPlayerInst; 6.36 + 6.37 + // song list 6.38 + private ArrayList<Song> songPlayList; 6.39 + 6.40 + // position within list of song currently playing in the MediaPlayer 6.41 + private int songPosnInList; 6.42 + 6.43 + //This is used to connect an instance of this service to Activities that use it 6.44 + private final IBinder musicBinderInst = new MusicBinder(); 6.45 + 6.46 + public MusicService() { 6.47 + } 6.48 + 6.49 +//============== Setup and Connect (bind) ============= 6.50 + public void onCreate(){ 6.51 + //create the service 6.52 + super.onCreate(); 6.53 + 6.54 + //initialize position 6.55 + songPosnInList =0; 6.56 + 6.57 + //create mediaPlayerInst, which is a singleton, that is prepared for each song, then 6.58 + // makes the audio for that song happen 6.59 + mediaPlayerInst = new MediaPlayer(); 6.60 + initMusicPlayer(); 6.61 + } 6.62 + 6.63 + public void initMusicPlayer(){ 6.64 + //set mediaPlayerInst properties 6.65 + mediaPlayerInst.setWakeMode(getApplicationContext(), 6.66 + PowerManager.PARTIAL_WAKE_LOCK); 6.67 + mediaPlayerInst.setAudioStreamType(AudioManager.STREAM_MUSIC); 6.68 + mediaPlayerInst.setOnPreparedListener(this); 6.69 + mediaPlayerInst.setOnCompletionListener(this); 6.70 + mediaPlayerInst.setOnErrorListener(this); 6.71 + } 6.72 + 6.73 + //Inner class, an instance of which is created as part of connecting Activity to this Service 6.74 + public class MusicBinder extends Binder { 6.75 + MusicService getService() { 6.76 + return MusicService.this; 6.77 + } 6.78 + } 6.79 + 6.80 + @Override 6.81 + public IBinder onBind(Intent intent) { 6.82 + return musicBinderInst; //the instance of MusicBinder created as instance var above 6.83 + } 6.84 + @Override 6.85 + public boolean onUnbind(Intent intent){ 6.86 + mediaPlayerInst.stop(); 6.87 + mediaPlayerInst.release(); 6.88 + return false; 6.89 + } 6.90 + 6.91 +//========================================== 6.92 + 6.93 + public void setList(ArrayList<Song> theSongs){ 6.94 + songPlayList =theSongs; 6.95 + } 6.96 + 6.97 + public void setSong(int songIndex){ 6.98 + songPosnInList =songIndex; 6.99 + } 6.100 + 6.101 + public void playSong(){ 6.102 + //play a song 6.103 + mediaPlayerInst.reset(); 6.104 + 6.105 + //get the song from the list, extract the ID for it using its Song object, and cast as a URI 6.106 + //get song 6.107 + Song playSong = songPlayList.get(songPosnInList); 6.108 + 6.109 + //get id 6.110 + long currSong = playSong.getID(); 6.111 + 6.112 + //set uri 6.113 + Uri trackUri = ContentUris.withAppendedId( 6.114 + android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, 6.115 + currSong); 6.116 + 6.117 + //set this URI as the data source for the MediaPlayer instance, 6.118 + try{ 6.119 + mediaPlayerInst.setDataSource(getApplicationContext(), trackUri); 6.120 + } 6.121 + catch(Exception e){ 6.122 + Log.e("MUSIC SERVICE", "Error setting data source", e); 6.123 + } 6.124 + 6.125 + //trigger the MediaPlayer to set itself up, open the songfile, and be ready to start playing 6.126 + // when done with all that, will call back to this object's "onPrepared" 6.127 + mediaPlayerInst.prepareAsync(); 6.128 + } 6.129 + 6.130 + @Override 6.131 + public void onPrepared(MediaPlayer preparedMediaPlayer) { 6.132 + //start playback 6.133 + preparedMediaPlayer.start(); 6.134 + } 6.135 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/app/src/main/java/com/example/friendstream/friendstream/PickingSongs.java Mon Apr 20 17:11:10 2015 +0300 7.3 @@ -0,0 +1,245 @@ 7.4 +/* 7.5 +Based on these tutorials: 7.6 +http://code.tutsplus.com/tutorials/create-a-music-player-on-android-project-setup--mobile-22764 7.7 + */ 7.8 + 7.9 +package com.example.friendstream.friendstream; 7.10 + 7.11 +import com.example.friendstream.friendstream.util.SystemUiHider; 7.12 + 7.13 +import android.annotation.TargetApi; 7.14 +import android.app.Activity; 7.15 +import android.os.Build; 7.16 +import android.os.Bundle; 7.17 +import android.os.Handler; 7.18 +import android.view.MotionEvent; 7.19 +import android.view.View; 7.20 +import android.os.IBinder; 7.21 +import android.content.ComponentName; 7.22 +import android.content.Context; 7.23 +import android.content.Intent; 7.24 +import android.content.ServiceConnection; 7.25 +import android.view.MenuItem; 7.26 +import android.view.View; 7.27 +import com.example.friendstream.friendstream.MusicService.MusicBinder; 7.28 + 7.29 + 7.30 +/** 7.31 + * An example full-screen activity that shows and hides the system UI (i.e. 7.32 + * status bar and navigation/system bar) with user interaction. 7.33 + * 7.34 + * @see SystemUiHider 7.35 + */ 7.36 +public class PickingSongs extends Activity { 7.37 + /** 7.38 + * Whether or not the system UI should be auto-hidden after 7.39 + * {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds. 7.40 + */ 7.41 + private static final boolean AUTO_HIDE = true; 7.42 + 7.43 + /** 7.44 + * If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after 7.45 + * user interaction before hiding the system UI. 7.46 + */ 7.47 + private static final int AUTO_HIDE_DELAY_MILLIS = 3000; 7.48 + 7.49 + /** 7.50 + * If set, will toggle the system UI visibility upon interaction. Otherwise, 7.51 + * will show the system UI visibility upon interaction. 7.52 + */ 7.53 + private static final boolean TOGGLE_ON_CLICK = true; 7.54 + 7.55 + /** 7.56 + * The flags to pass to {@link SystemUiHider#getInstance}. 7.57 + */ 7.58 + private static final int HIDER_FLAGS = SystemUiHider.FLAG_HIDE_NAVIGATION; 7.59 + 7.60 + /** 7.61 + * The instance of the {@link SystemUiHider} for this activity. 7.62 + */ 7.63 + private SystemUiHider mSystemUiHider; 7.64 + 7.65 + private MusicService musicSrv; 7.66 + private Intent playIntent; 7.67 + private boolean musicBound=false; 7.68 + 7.69 + 7.70 + @Override 7.71 + protected void onCreate(Bundle savedInstanceState) { 7.72 + super.onCreate(savedInstanceState); 7.73 + 7.74 + setContentView(R.layout.activity_picking_songs); 7.75 + 7.76 + final View controlsView = findViewById(R.id.fullscreen_content_controls); 7.77 + final View contentView = findViewById(R.id.fullscreen_content); 7.78 + 7.79 + // Set up an instance of SystemUiHider to control the system UI for 7.80 + // this activity. 7.81 + mSystemUiHider = SystemUiHider.getInstance(this, contentView, HIDER_FLAGS); 7.82 + mSystemUiHider.setup(); 7.83 + mSystemUiHider 7.84 + .setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() { 7.85 + // Cached values. 7.86 + int mControlsHeight; 7.87 + int mShortAnimTime; 7.88 + 7.89 + @Override 7.90 + @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2) 7.91 + public void onVisibilityChange(boolean visible) { 7.92 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { 7.93 + // If the ViewPropertyAnimator API is available 7.94 + // (Honeycomb MR2 and later), use it to animate the 7.95 + // in-layout UI controls at the bottom of the 7.96 + // screen. 7.97 + if (mControlsHeight == 0) { 7.98 + mControlsHeight = controlsView.getHeight(); 7.99 + } 7.100 + if (mShortAnimTime == 0) { 7.101 + mShortAnimTime = getResources().getInteger( 7.102 + android.R.integer.config_shortAnimTime); 7.103 + } 7.104 + controlsView.animate() 7.105 + .translationY(visible ? 0 : mControlsHeight) 7.106 + .setDuration(mShortAnimTime); 7.107 + } else { 7.108 + // If the ViewPropertyAnimator APIs aren't 7.109 + // available, simply show or hide the in-layout UI 7.110 + // controls. 7.111 + controlsView.setVisibility(visible ? View.VISIBLE : View.GONE); 7.112 + } 7.113 + 7.114 + if (visible && AUTO_HIDE) { 7.115 + // Schedule a hide(). 7.116 + delayedHide(AUTO_HIDE_DELAY_MILLIS); 7.117 + } 7.118 + } 7.119 + }); 7.120 + 7.121 + // Set up the user interaction to manually show or hide the system UI. 7.122 + contentView.setOnClickListener(new View.OnClickListener() { 7.123 + @Override 7.124 + public void onClick(View view) { 7.125 + if (TOGGLE_ON_CLICK) { 7.126 + mSystemUiHider.toggle(); 7.127 + } else { 7.128 + mSystemUiHider.show(); 7.129 + } 7.130 + } 7.131 + }); 7.132 + 7.133 + // Upon interacting with UI controls, delay any scheduled hide() 7.134 + // operations to prevent the jarring behavior of controls going away 7.135 + // while interacting with the UI. 7.136 + findViewById(R.id.dummy_button).setOnTouchListener(mDelayHideTouchListener); 7.137 + } 7.138 + 7.139 + // This Activity controls the Service that makes the audio of a playlist happen. 7.140 + // Bind this Activity to the Service class, using an anonymous Intent class 7.141 + // The callback methods essentially inform the Activity instance of when it is connected 7.142 + // to the Service instance. The callback sets a reference to the Service (which it gets via 7.143 + // the MusicBinder instance inside the Service) and a flag. 7.144 + // The bind process is what calls the onServiceConnected.. the whole MusicBinder thing looks 7.145 + // pretty messed up.. these guys twist their brains in bizarre ways sometimes.. 7.146 + private ServiceConnection musicConnection = new ServiceConnection(){ 7.147 + 7.148 + @Override 7.149 + public void onServiceConnected(ComponentName name, IBinder service) { 7.150 + MusicBinder binder = (MusicBinder)service; 7.151 + //get service 7.152 + musicSrv = binder.getService(); 7.153 + //pass list 7.154 + musicSrv.setList(songList); 7.155 + musicBound = true; 7.156 + } 7.157 + 7.158 + @Override 7.159 + public void onServiceDisconnected(ComponentName name) { 7.160 + musicBound = false; 7.161 + } 7.162 + }; 7.163 + 7.164 + // added an onClick attribute to the layout for each item in the song list.. calls this.. 7.165 + public void songPicked(View view){ 7.166 + musicSrv.setSong(Integer.parseInt(view.getTag().toString())); 7.167 + musicSrv.playSong(); 7.168 + } 7.169 + 7.170 + 7.171 + // implement the end button we added to the main menu 7.172 + @Override 7.173 + public boolean onOptionsItemSelected(MenuItem item) { 7.174 + //menu item selected 7.175 + switch (item.getItemId()) { 7.176 + case R.id.action_shuffle: 7.177 + //shuffle 7.178 + break; 7.179 + case R.id.action_end: 7.180 + stopService(playIntent); 7.181 + musicSrv=null; 7.182 + System.exit(0); 7.183 + break; 7.184 + } 7.185 + return super.onOptionsItemSelected(item); 7.186 + } 7.187 + 7.188 + @Override 7.189 + protected void onDestroy() { 7.190 + stopService(playIntent); 7.191 + musicSrv=null; 7.192 + super.onDestroy(); 7.193 + } 7.194 + 7.195 + @Override 7.196 + protected void onStart() { 7.197 + super.onStart(); 7.198 + if( playIntent==null ){ 7.199 + playIntent = new Intent(this, MusicService.class); 7.200 + bindService(playIntent, musicConnection, Context.BIND_AUTO_CREATE); 7.201 + startService(playIntent); 7.202 + } 7.203 + } 7.204 + 7.205 + 7.206 + @Override 7.207 + protected void onPostCreate(Bundle savedInstanceState) { 7.208 + super.onPostCreate(savedInstanceState); 7.209 + 7.210 + // Trigger the initial hide() shortly after the activity has been 7.211 + // created, to briefly hint to the user that UI controls 7.212 + // are available. 7.213 + delayedHide(100); 7.214 + } 7.215 + 7.216 + 7.217 + /** 7.218 + * Touch listener to use for in-layout UI controls to delay hiding the 7.219 + * system UI. This is to prevent the jarring behavior of controls going away 7.220 + * while interacting with activity UI. 7.221 + */ 7.222 + View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() { 7.223 + @Override 7.224 + public boolean onTouch(View view, MotionEvent motionEvent) { 7.225 + if (AUTO_HIDE) { 7.226 + delayedHide(AUTO_HIDE_DELAY_MILLIS); 7.227 + } 7.228 + return false; 7.229 + } 7.230 + }; 7.231 + 7.232 + Handler mHideHandler = new Handler(); 7.233 + Runnable mHideRunnable = new Runnable() { 7.234 + @Override 7.235 + public void run() { 7.236 + mSystemUiHider.hide(); 7.237 + } 7.238 + }; 7.239 + 7.240 + /** 7.241 + * Schedules a call to hide() in [delay] milliseconds, canceling any 7.242 + * previously scheduled calls. 7.243 + */ 7.244 + private void delayedHide(int delayMillis) { 7.245 + mHideHandler.removeCallbacks(mHideRunnable); 7.246 + mHideHandler.postDelayed(mHideRunnable, delayMillis); 7.247 + } 7.248 +}
8.1 --- a/app/src/main/java/com/example/friendstream/friendstream/Service_Play_Song.java Mon Apr 20 14:57:37 2015 +0300 8.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 8.3 @@ -1,16 +0,0 @@ 8.4 -package com.example.friendstream.friendstream; 8.5 - 8.6 -import android.app.Service; 8.7 -import android.content.Intent; 8.8 -import android.os.IBinder; 8.9 - 8.10 -public class Service_Play_Song extends Service { 8.11 - public Service_Play_Song() { 8.12 - } 8.13 - 8.14 - @Override 8.15 - public IBinder onBind(Intent intent) { 8.16 - // TODO: Return the communication channel to the service. 8.17 - throw new UnsupportedOperationException("Not yet implemented"); 8.18 - } 8.19 -}
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/app/src/main/java/com/example/friendstream/friendstream/util/SystemUiHider.java Mon Apr 20 17:11:10 2015 +0300 9.3 @@ -0,0 +1,172 @@ 9.4 +package com.example.friendstream.friendstream.util; 9.5 + 9.6 +import android.app.Activity; 9.7 +import android.os.Build; 9.8 +import android.view.View; 9.9 + 9.10 +/** 9.11 + * A utility class that helps with showing and hiding system UI such as the 9.12 + * status bar and navigation/system bar. This class uses backward-compatibility 9.13 + * techniques described in <a href= 9.14 + * "http://developer.android.com/training/backward-compatible-ui/index.html"> 9.15 + * Creating Backward-Compatible UIs</a> to ensure that devices running any 9.16 + * version of ndroid OS are supported. More specifically, there are separate 9.17 + * implementations of this abstract class: for newer devices, 9.18 + * {@link #getInstance} will return a {@link SystemUiHiderHoneycomb} instance, 9.19 + * while on older devices {@link #getInstance} will return a 9.20 + * {@link SystemUiHiderBase} instance. 9.21 + * <p/> 9.22 + * For more on system bars, see <a href= 9.23 + * "http://developer.android.com/design/get-started/ui-overview.html#system-bars" 9.24 + * > System Bars</a>. 9.25 + * 9.26 + * @see android.view.View#setSystemUiVisibility(int) 9.27 + * @see android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN 9.28 + */ 9.29 +public abstract class SystemUiHider { 9.30 + /** 9.31 + * When this flag is set, the 9.32 + * {@link android.view.WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN} 9.33 + * flag will be set on older devices, making the status bar "float" on top 9.34 + * of the activity layout. This is most useful when there are no controls at 9.35 + * the top of the activity layout. 9.36 + * <p/> 9.37 + * This flag isn't used on newer devices because the <a 9.38 + * href="http://developer.android.com/design/patterns/actionbar.html">action 9.39 + * bar</a>, the most important structural element of an Android app, should 9.40 + * be visible and not obscured by the system UI. 9.41 + */ 9.42 + public static final int FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES = 0x1; 9.43 + 9.44 + /** 9.45 + * When this flag is set, {@link #show()} and {@link #hide()} will toggle 9.46 + * the visibility of the status bar. If there is a navigation bar, show and 9.47 + * hide will toggle low profile mode. 9.48 + */ 9.49 + public static final int FLAG_FULLSCREEN = 0x2; 9.50 + 9.51 + /** 9.52 + * When this flag is set, {@link #show()} and {@link #hide()} will toggle 9.53 + * the visibility of the navigation bar, if it's present on the device and 9.54 + * the device allows hiding it. In cases where the navigation bar is present 9.55 + * but cannot be hidden, show and hide will toggle low profile mode. 9.56 + */ 9.57 + public static final int FLAG_HIDE_NAVIGATION = FLAG_FULLSCREEN | 0x4; 9.58 + 9.59 + /** 9.60 + * The activity associated with this UI hider object. 9.61 + */ 9.62 + protected Activity mActivity; 9.63 + 9.64 + /** 9.65 + * The view on which {@link View#setSystemUiVisibility(int)} will be called. 9.66 + */ 9.67 + protected View mAnchorView; 9.68 + 9.69 + /** 9.70 + * The current UI hider flags. 9.71 + * 9.72 + * @see #FLAG_FULLSCREEN 9.73 + * @see #FLAG_HIDE_NAVIGATION 9.74 + * @see #FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES 9.75 + */ 9.76 + protected int mFlags; 9.77 + 9.78 + /** 9.79 + * The current visibility callback. 9.80 + */ 9.81 + protected OnVisibilityChangeListener mOnVisibilityChangeListener = sDummyListener; 9.82 + 9.83 + /** 9.84 + * Creates and returns an instance of {@link SystemUiHider} that is 9.85 + * appropriate for this device. The object will be either a 9.86 + * {@link SystemUiHiderBase} or {@link SystemUiHiderHoneycomb} depending on 9.87 + * the device. 9.88 + * 9.89 + * @param activity The activity whose window's system UI should be 9.90 + * controlled by this class. 9.91 + * @param anchorView The view on which 9.92 + * {@link View#setSystemUiVisibility(int)} will be called. 9.93 + * @param flags Either 0 or any combination of {@link #FLAG_FULLSCREEN}, 9.94 + * {@link #FLAG_HIDE_NAVIGATION}, and 9.95 + * {@link #FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES}. 9.96 + */ 9.97 + public static SystemUiHider getInstance(Activity activity, View anchorView, int flags) { 9.98 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { 9.99 + return new SystemUiHiderHoneycomb(activity, anchorView, flags); 9.100 + } else { 9.101 + return new SystemUiHiderBase(activity, anchorView, flags); 9.102 + } 9.103 + } 9.104 + 9.105 + protected SystemUiHider(Activity activity, View anchorView, int flags) { 9.106 + mActivity = activity; 9.107 + mAnchorView = anchorView; 9.108 + mFlags = flags; 9.109 + } 9.110 + 9.111 + /** 9.112 + * Sets up the system UI hider. Should be called from 9.113 + * {@link Activity#onCreate}. 9.114 + */ 9.115 + public abstract void setup(); 9.116 + 9.117 + /** 9.118 + * Returns whether or not the system UI is visible. 9.119 + */ 9.120 + public abstract boolean isVisible(); 9.121 + 9.122 + /** 9.123 + * Hide the system UI. 9.124 + */ 9.125 + public abstract void hide(); 9.126 + 9.127 + /** 9.128 + * Show the system UI. 9.129 + */ 9.130 + public abstract void show(); 9.131 + 9.132 + /** 9.133 + * Toggle the visibility of the system UI. 9.134 + */ 9.135 + public void toggle() { 9.136 + if (isVisible()) { 9.137 + hide(); 9.138 + } else { 9.139 + show(); 9.140 + } 9.141 + } 9.142 + 9.143 + /** 9.144 + * Registers a callback, to be triggered when the system UI visibility 9.145 + * changes. 9.146 + */ 9.147 + public void setOnVisibilityChangeListener(OnVisibilityChangeListener listener) { 9.148 + if (listener == null) { 9.149 + listener = sDummyListener; 9.150 + } 9.151 + 9.152 + mOnVisibilityChangeListener = listener; 9.153 + } 9.154 + 9.155 + /** 9.156 + * A dummy no-op callback for use when there is no other listener set. 9.157 + */ 9.158 + private static OnVisibilityChangeListener sDummyListener = new OnVisibilityChangeListener() { 9.159 + @Override 9.160 + public void onVisibilityChange(boolean visible) { 9.161 + } 9.162 + }; 9.163 + 9.164 + /** 9.165 + * A callback interface used to listen for system UI visibility changes. 9.166 + */ 9.167 + public interface OnVisibilityChangeListener { 9.168 + /** 9.169 + * Called when the system UI visibility has changed. 9.170 + * 9.171 + * @param visible True if the system UI is visible. 9.172 + */ 9.173 + public void onVisibilityChange(boolean visible); 9.174 + } 9.175 +}
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/app/src/main/java/com/example/friendstream/friendstream/util/SystemUiHiderBase.java Mon Apr 20 17:11:10 2015 +0300 10.3 @@ -0,0 +1,63 @@ 10.4 +package com.example.friendstream.friendstream.util; 10.5 + 10.6 +import android.app.Activity; 10.7 +import android.view.View; 10.8 +import android.view.WindowManager; 10.9 + 10.10 +/** 10.11 + * A base implementation of {@link SystemUiHider}. Uses APIs available in all 10.12 + * API levels to show and hide the status bar. 10.13 + */ 10.14 +public class SystemUiHiderBase extends SystemUiHider { 10.15 + /** 10.16 + * Whether or not the system UI is currently visible. This is a cached value 10.17 + * from calls to {@link #hide()} and {@link #show()}. 10.18 + */ 10.19 + private boolean mVisible = true; 10.20 + 10.21 + /** 10.22 + * Constructor not intended to be called by clients. Use 10.23 + * {@link SystemUiHider#getInstance} to obtain an instance. 10.24 + */ 10.25 + protected SystemUiHiderBase(Activity activity, View anchorView, int flags) { 10.26 + super(activity, anchorView, flags); 10.27 + } 10.28 + 10.29 + @Override 10.30 + public void setup() { 10.31 + if ((mFlags & FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES) == 0) { 10.32 + mActivity.getWindow().setFlags( 10.33 + WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN 10.34 + | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, 10.35 + WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN 10.36 + | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); 10.37 + } 10.38 + } 10.39 + 10.40 + @Override 10.41 + public boolean isVisible() { 10.42 + return mVisible; 10.43 + } 10.44 + 10.45 + @Override 10.46 + public void hide() { 10.47 + if ((mFlags & FLAG_FULLSCREEN) != 0) { 10.48 + mActivity.getWindow().setFlags( 10.49 + WindowManager.LayoutParams.FLAG_FULLSCREEN, 10.50 + WindowManager.LayoutParams.FLAG_FULLSCREEN); 10.51 + } 10.52 + mOnVisibilityChangeListener.onVisibilityChange(false); 10.53 + mVisible = false; 10.54 + } 10.55 + 10.56 + @Override 10.57 + public void show() { 10.58 + if ((mFlags & FLAG_FULLSCREEN) != 0) { 10.59 + mActivity.getWindow().setFlags( 10.60 + 0, 10.61 + WindowManager.LayoutParams.FLAG_FULLSCREEN); 10.62 + } 10.63 + mOnVisibilityChangeListener.onVisibilityChange(true); 10.64 + mVisible = true; 10.65 + } 10.66 +}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/app/src/main/java/com/example/friendstream/friendstream/util/SystemUiHiderHoneycomb.java Mon Apr 20 17:11:10 2015 +0300 11.3 @@ -0,0 +1,141 @@ 11.4 +package com.example.friendstream.friendstream.util; 11.5 + 11.6 +import android.annotation.TargetApi; 11.7 +import android.app.Activity; 11.8 +import android.os.Build; 11.9 +import android.view.View; 11.10 +import android.view.WindowManager; 11.11 + 11.12 +/** 11.13 + * An API 11+ implementation of {@link SystemUiHider}. Uses APIs available in 11.14 + * Honeycomb and later (specifically {@link View#setSystemUiVisibility(int)}) to 11.15 + * show and hide the system UI. 11.16 + */ 11.17 +@TargetApi(Build.VERSION_CODES.HONEYCOMB) 11.18 +public class SystemUiHiderHoneycomb extends SystemUiHiderBase { 11.19 + /** 11.20 + * Flags for {@link View#setSystemUiVisibility(int)} to use when showing the 11.21 + * system UI. 11.22 + */ 11.23 + private int mShowFlags; 11.24 + 11.25 + /** 11.26 + * Flags for {@link View#setSystemUiVisibility(int)} to use when hiding the 11.27 + * system UI. 11.28 + */ 11.29 + private int mHideFlags; 11.30 + 11.31 + /** 11.32 + * Flags to test against the first parameter in 11.33 + * {@link android.view.View.OnSystemUiVisibilityChangeListener#onSystemUiVisibilityChange(int)} 11.34 + * to determine the system UI visibility state. 11.35 + */ 11.36 + private int mTestFlags; 11.37 + 11.38 + /** 11.39 + * Whether or not the system UI is currently visible. This is cached from 11.40 + * {@link android.view.View.OnSystemUiVisibilityChangeListener}. 11.41 + */ 11.42 + private boolean mVisible = true; 11.43 + 11.44 + /** 11.45 + * Constructor not intended to be called by clients. Use 11.46 + * {@link SystemUiHider#getInstance} to obtain an instance. 11.47 + */ 11.48 + protected SystemUiHiderHoneycomb(Activity activity, View anchorView, int flags) { 11.49 + super(activity, anchorView, flags); 11.50 + 11.51 + mShowFlags = View.SYSTEM_UI_FLAG_VISIBLE; 11.52 + mHideFlags = View.SYSTEM_UI_FLAG_LOW_PROFILE; 11.53 + mTestFlags = View.SYSTEM_UI_FLAG_LOW_PROFILE; 11.54 + 11.55 + if ((mFlags & FLAG_FULLSCREEN) != 0) { 11.56 + // If the client requested fullscreen, add flags relevant to hiding 11.57 + // the status bar. Note that some of these constants are new as of 11.58 + // API 16 (Jelly Bean). It is safe to use them, as they are inlined 11.59 + // at compile-time and do nothing on pre-Jelly Bean devices. 11.60 + mShowFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; 11.61 + mHideFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 11.62 + | View.SYSTEM_UI_FLAG_FULLSCREEN; 11.63 + } 11.64 + 11.65 + if ((mFlags & FLAG_HIDE_NAVIGATION) != 0) { 11.66 + // If the client requested hiding navigation, add relevant flags. 11.67 + mShowFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; 11.68 + mHideFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 11.69 + | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; 11.70 + mTestFlags |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; 11.71 + } 11.72 + } 11.73 + 11.74 + /** 11.75 + * {@inheritDoc} 11.76 + */ 11.77 + @Override 11.78 + public void setup() { 11.79 + mAnchorView.setOnSystemUiVisibilityChangeListener(mSystemUiVisibilityChangeListener); 11.80 + } 11.81 + 11.82 + /** 11.83 + * {@inheritDoc} 11.84 + */ 11.85 + @Override 11.86 + public void hide() { 11.87 + mAnchorView.setSystemUiVisibility(mHideFlags); 11.88 + } 11.89 + 11.90 + /** 11.91 + * {@inheritDoc} 11.92 + */ 11.93 + @Override 11.94 + public void show() { 11.95 + mAnchorView.setSystemUiVisibility(mShowFlags); 11.96 + } 11.97 + 11.98 + /** 11.99 + * {@inheritDoc} 11.100 + */ 11.101 + @Override 11.102 + public boolean isVisible() { 11.103 + return mVisible; 11.104 + } 11.105 + 11.106 + private View.OnSystemUiVisibilityChangeListener mSystemUiVisibilityChangeListener 11.107 + = new View.OnSystemUiVisibilityChangeListener() { 11.108 + @Override 11.109 + public void onSystemUiVisibilityChange(int vis) { 11.110 + // Test against mTestFlags to see if the system UI is visible. 11.111 + if ((vis & mTestFlags) != 0) { 11.112 + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { 11.113 + // Pre-Jelly Bean, we must manually hide the action bar 11.114 + // and use the old window flags API. 11.115 + mActivity.getActionBar().hide(); 11.116 + mActivity.getWindow().setFlags( 11.117 + WindowManager.LayoutParams.FLAG_FULLSCREEN, 11.118 + WindowManager.LayoutParams.FLAG_FULLSCREEN); 11.119 + } 11.120 + 11.121 + // Trigger the registered listener and cache the visibility 11.122 + // state. 11.123 + mOnVisibilityChangeListener.onVisibilityChange(false); 11.124 + mVisible = false; 11.125 + 11.126 + } else { 11.127 + mAnchorView.setSystemUiVisibility(mShowFlags); 11.128 + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { 11.129 + // Pre-Jelly Bean, we must manually show the action bar 11.130 + // and use the old window flags API. 11.131 + mActivity.getActionBar().show(); 11.132 + mActivity.getWindow().setFlags( 11.133 + 0, 11.134 + WindowManager.LayoutParams.FLAG_FULLSCREEN); 11.135 + } 11.136 + 11.137 + // Trigger the registered listener and cache the visibility 11.138 + // state. 11.139 + mOnVisibilityChangeListener.onVisibilityChange(true); 11.140 + mVisible = true; 11.141 + } 11.142 + } 11.143 + }; 11.144 +}
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/app/src/main/res/layout/activity_picking_songs.xml Mon Apr 20 17:11:10 2015 +0300 12.3 @@ -0,0 +1,31 @@ 12.4 +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 12.5 + xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 12.6 + android:layout_height="match_parent" android:background="#0099cc" tools:context=".PickingSongs"> 12.7 + 12.8 + <!-- The primary full-screen view. This can be replaced with whatever view 12.9 + is needed to present your content, e.g. VideoView, SurfaceView, 12.10 + TextureView, etc. --> 12.11 + <TextView android:id="@+id/fullscreen_content" android:layout_width="match_parent" 12.12 + android:layout_height="match_parent" android:keepScreenOn="true" android:textColor="#33b5e5" 12.13 + android:textStyle="bold" android:textSize="50sp" android:gravity="center" 12.14 + android:text="@string/dummy_content" /> 12.15 + 12.16 + <!-- This FrameLayout insets its children based on system windows using 12.17 + android:fitsSystemWindows. --> 12.18 + <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" 12.19 + android:fitsSystemWindows="true"> 12.20 + 12.21 + <LinearLayout android:id="@+id/fullscreen_content_controls" style="?metaButtonBarStyle" 12.22 + android:layout_width="match_parent" android:layout_height="wrap_content" 12.23 + android:layout_gravity="bottom|center_horizontal" 12.24 + android:background="@color/black_overlay" android:orientation="horizontal" 12.25 + tools:ignore="UselessParent"> 12.26 + 12.27 + <Button android:id="@+id/dummy_button" style="?metaButtonBarButtonStyle" 12.28 + android:layout_width="0dp" android:layout_height="wrap_content" 12.29 + android:layout_weight="1" android:text="@string/dummy_button" /> 12.30 + 12.31 + </LinearLayout> 12.32 + </FrameLayout> 12.33 + 12.34 +</FrameLayout>
13.1 Binary file app/src/main/res/mipmap-hdpi/ic_launcher.png has changed
14.1 Binary file app/src/main/res/mipmap-mdpi/ic_launcher.png has changed
15.1 Binary file app/src/main/res/mipmap-xhdpi/ic_launcher.png has changed
16.1 Binary file app/src/main/res/mipmap-xxhdpi/ic_launcher.png has changed
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 17.2 +++ b/app/src/main/res/values-v11/styles.xml Mon Apr 20 17:11:10 2015 +0300 17.3 @@ -0,0 +1,15 @@ 17.4 +<resources> 17.5 + 17.6 + <style name="FullscreenTheme" parent="android:Theme.Holo"> 17.7 + <item name="android:actionBarStyle">@style/FullscreenActionBarStyle</item> 17.8 + <item name="android:windowActionBarOverlay">true</item> 17.9 + <item name="android:windowBackground">@null</item> 17.10 + <item name="metaButtonBarStyle">?android:attr/buttonBarStyle</item> 17.11 + <item name="metaButtonBarButtonStyle">?android:attr/buttonBarButtonStyle</item> 17.12 + </style> 17.13 + 17.14 + <style name="FullscreenActionBarStyle" parent="android:Widget.Holo.ActionBar"> 17.15 + <item name="android:background">@color/black_overlay</item> 17.16 + </style> 17.17 + 17.18 +</resources>
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 18.2 +++ b/app/src/main/res/values/attrs.xml Mon Apr 20 17:11:10 2015 +0300 18.3 @@ -0,0 +1,12 @@ 18.4 +<resources> 18.5 + 18.6 + <!-- Declare custom theme attributes that allow changing which styles are 18.7 + used for button bars depending on the API level. 18.8 + ?android:attr/buttonBarStyle is new as of API 11 so this is 18.9 + necessary to support previous API levels. --> 18.10 + <declare-styleable name="ButtonBarContainerTheme"> 18.11 + <attr name="metaButtonBarStyle" format="reference" /> 18.12 + <attr name="metaButtonBarButtonStyle" format="reference" /> 18.13 + </declare-styleable> 18.14 + 18.15 +</resources>
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 19.2 +++ b/app/src/main/res/values/colors.xml Mon Apr 20 17:11:10 2015 +0300 19.3 @@ -0,0 +1,5 @@ 19.4 +<resources> 19.5 + 19.6 + <color name="black_overlay">#66000000</color> 19.7 + 19.8 +</resources>
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 20.2 +++ b/app/src/main/res/values/strings.xml Mon Apr 20 17:11:10 2015 +0300 20.3 @@ -0,0 +1,6 @@ 20.4 +<resources> 20.5 + <string name="app_name">FriendStream</string> 20.6 + 20.7 + <string name="dummy_button">Dummy Button</string> 20.8 + <string name="dummy_content">DUMMY\nCONTENT</string> 20.9 +</resources>
21.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 21.2 +++ b/app/src/main/res/values/styles.xml Mon Apr 20 17:11:10 2015 +0300 21.3 @@ -0,0 +1,27 @@ 21.4 +<resources> 21.5 + 21.6 + <!-- Base application theme. --> 21.7 + <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 21.8 + <!-- Customize your theme here. --> 21.9 + </style> 21.10 + 21.11 + <style name="FullscreenTheme" parent="android:Theme.NoTitleBar"> 21.12 + <item name="android:windowContentOverlay">@null</item> 21.13 + <item name="android:windowBackground">@null</item> 21.14 + <item name="metaButtonBarStyle">@style/ButtonBar</item> 21.15 + <item name="metaButtonBarButtonStyle">@style/ButtonBarButton</item> 21.16 + </style> 21.17 + 21.18 + <!-- Backward-compatible version of ?android:attr/buttonBarStyle --> 21.19 + <style name="ButtonBar"> 21.20 + <item name="android:paddingLeft">2dp</item> 21.21 + <item name="android:paddingTop">5dp</item> 21.22 + <item name="android:paddingRight">2dp</item> 21.23 + <item name="android:paddingBottom">0dp</item> 21.24 + <item name="android:background">@android:drawable/bottom_bar</item> 21.25 + </style> 21.26 + 21.27 + <!-- Backward-compatible version of ?android:attr/buttonBarButtonStyle --> 21.28 + <style name="ButtonBarButton" /> 21.29 + 21.30 +</resources>
