このAndroidプロジェクトは、チャットや何らかの情報を前面に表示するためのViewです
AndroidのAPI 14以降に対応しています
動作の詳細はYouTubeの動画を確認してください
SimpleFloating
FloatingAd
Target Sdk Version : 22
Min Sdk Version : 14
##How to use
-
FloatingViewを使用したいプロジェクトに本プロジェクトのlibraryを追加します
-
FloatingViewを表示するためのServiceを定義します
public class ChatHeadService extends Service {
・・・
}
- FloatingViewに表示するViewの設定を行います(サンプルではonStartCommandで行っています)
final LayoutInflater inflater = LayoutInflater.from(this);
final ImageView iconView = (ImageView) inflater.inflate(R.layout.widget_chathead, null, false);
iconView.setOnClickListener(・・・);
- FloatingViewManagerを使用して、FloatingViewの設定を行います
mFloatingViewManager = new FloatingViewManager(this, this);
mFloatingViewManager.setFixedTrashIconImage(R.drawable.ic_trash_fixed);
mFloatingViewManager.setActionTrashIconImage(R.drawable.ic_trash_action);
mFloatingViewManager.addViewToWindow(iconView, FloatingViewManager.SHAPE_CIRCLE, (int) (16 * metrics.density));
なお、FloatingViewManagerの第2引数はFloatingViewListenerです
これは、FloatingViewを終了する際に呼び出される処理(onFinishFloatingView)を記述します
@Override
public void onFinishFloatingView() {
stopSelf();
}
- AndroidManifestにパーミッションを追加します
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.VIBRATE"/>
- AndroidManifestにServiceを定義します
例)
<application ・・・>
・・・
<!-- デモ表示サービス -->
<service
android:name="jp.co.recruit_lifestyle.sample.service.ChatHeadService"
android:exported="false"/>
・・・
</application>
- Serviceを開始する処理を記述します(以下はFragmentの例)
final Activity activity = getActivity();
activity.startService(new Intent(activity, ChatHeadService.class));
補足)FloatingAdServiceを動作させるためには、string.xmlのad_unit_idを自身の広告ID(インタースティシャル)で置き換えてください
<string name="ad_unit_id">ADD_YOUR_UNIT_ID</string>
FloatingView is owned and maintained by RECRUIT LIFESTYLE CO., LTD.
FloatingView was originally created by Yoshihide Sogawa
##License
Copyright 2015 RECRUIT LIFESTYLE CO., LTD.
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.