Set wallpaper image as lockscreen background Trick

Uncategorized
Question: import android.app.Service; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.graphics.PixelFormat; import android.os.IBinder; import android.view.WindowManager; import android.widget.ImageView; public class LockScreenImageService extends Service { private BroadcastReceiver mReceiver; private boolean isShowing = false; @Override public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } private WindowManager windowManager; private ImageView imageView; WindowManager.LayoutParams params; @Override public void onCreate() { super.onCreate(); windowManager = (WindowManager)getSystemService(WINDOW_SERVICE); imageView = new ImageView(this); imageView.setBackgroundColor(this.getResources().getColor(R.color.colorAccent)); imageView.setImageDrawable(this.getResources().getDrawable(R.drawable.ic_img)); //set parameters for the imageView params = new WindowManager.LayoutParams( WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER, PixelFormat.TRANSPARENT); //Register receiver for determining screen off and if user // is present mReceiver = new LockScreenStateReceiver(); IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF); filter.addAction(Intent.ACTION_USER_PRESENT); registerReceiver(mReceiver, filter); } @Override public int onStartCommand(Intent intent, int flags, int startId) { return START_STICKY; } public class LockScreenStateReceiver extends BroadcastReceiver { @Override public…
Read More

Download a epub file through axios & react-file-download lbraries in reactjs

reactjs
Question: I am trying to fetch an epub file from my server using axios and react-file-download. The download code looks as follows - const FileDownload = require('react-file-download'); export const handleDownload = (url, bookName) => { axios.get(url, { headers: { 'Content-Type': 'application/octet-stream' } }).then((res) => { FileDownload(res.data, bookName+'.epub'); }); } The file is downloaded. I see different size on disc for different books. But they just don't open. What am i missing? Answer: Read more
Read More

mysql Table Sum of Positive and Negative Numbers

Uncategorized
Question: I have a column which has positive & negative numbers. Is it possible to have sum of all the positive numbers in Col1, negative numbers in Col2 and (Col1 - Col2) in Col3. Then sort by the last Col. Current table New Table ID Score ID Pos Neg Diff 1 3 3 5 0 5 1 1 1 4 1 3 1 -1 2 2 1 1 2 1 2 -1 2 1 3 3 3 1 3 1 This gives me the total but i would like to list the Pos and Neg numbers as well. SELECT ID, SUM(Score) as total FROM results GROUP BY ID ORDER BY total DESC Answer: Just use a standard pivot query with separate conditional aggregations for the positive and negative numbers. SELECT…
Read More

Android first ImageView in vertical LinearLayout stretching

Uncategorized
Question: I'm creating the above popup, the content of which consists of rows of horizontal LinearLayout views within a main vertical LinearLayout. Each horizontal LinearLayout contains one ImageView and one TextView. I'm creating this within a PopupWindow, and doing so programmatically so that I can change the ImageView source as required. As you can see the first icon seems to take up a lot of space, despite having the same code generating it as the other icons. Below is the code:LinearLayout verticalLayout = new LinearLayout(context); verticalLayout.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams mainLayoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); verticalLayout.setLayoutParams(mainLayoutParams); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams iconParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT); LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); //History row LinearLayout historyLayout = new LinearLayout(context); historyLayout.setLayoutParams(layoutParams); historyLayout.setOrientation(LinearLayout.HORIZONTAL); ImageView historyIcon = new ImageView(context); historyIcon.setImageResource(R.drawable.small_book_grey); historyIcon.setAdjustViewBounds(true); historyIcon.setLayoutParams(iconParams); historyLayout.addView(historyIcon); TextView…
Read More

How to format a js date?

Uncategorized
Question: I am writing this code but it seems I don't get the result I want. This is a Real Time Clock. This is the Result: Tue Aug 15 2017 13:34:09 GMT+0800 (China Standard Time) How Can I format the Date and Time to this: "Tue August 15, 2017 1:30pm" Answer: Try something like this var date = new Date(Date.UTC(2013, 1, 1, 14, 0, 0)); var options = { weekday: "long", year: "numeric", month: "short", day: "numeric", hour: "2-digit", minute: "2-digit" }; document.write(date.toLocaleTimeString("en-us", options)); // output:// ‎Friday‎, ‎Feb‎ ‎1‎, ‎2013‎ ‎06‎:‎00‎ ‎AM Read more
Read More

Callback can not be invoked properly, if the parameter is a bound function

Uncategorized
Question: When a function expects a callback as a param, I suppose it make sense to provide a bound function like this function invokeCb(cb){ cb(); } function test(x){ console.log(x) } const para="xyz"; invokeCb(test.bind(null,para)) //(1) invokeCb(()=>{test(para)}) //(2) I can not see anything wrong with (1). However, when it come to real world, I encounter some unexpected behaviour Here is a example, in redux store.subscribe( ()=>{(saveState.bind(null,store.getState()))()} ) can work while store.subscribe(saveState.bind(null,store.getState())) can not correctly, i.e. the store.getState() seems never invoked properly If you need more context. Here:https://egghead.io/lessons/javascript-redux-persisting-the-state-to-the-local-storage Maybe I missed some subtle differences between the two form, can anyone point it out? Answer: The differences are the time at which store.getState() is evaluated the return value (by using braces without return, you suppress it) let data = "abc"; function invokeCb(cb){ data =…
Read More

XML Export to Excel via XSLT – Add Bold Formatting

Uncategorized
Question: I'm generating a .xls Excel file from some XML data using an XSLT file - this is working well and generating a valid XLS file. I now need to extend this to made some of the cells bold. Here's my XML file: 0 Created: 15-August-2017 Name ID Category Number Amount Acme Corp Pty Ltd 123456 Category 1 1 $456.78 Demo Company Pty Ltd 987654 Category 2 1 $789.32 I would like this row to have the bold attribute assigned: Name ID Category Number Amount but not sure how to do about this in my XSLT file. The part of the XSLT that processes the rows is as follows: Answer: Read more
Read More

How to handle exception thrown when trying to propagate error to Observer.onError?

android
Question: I'm creating this app with RxJava, RxAndroid and Retrofit2. My query with Retrofit2:@POST("auth/sign_in") Observable signIn(@Header("email") String email, @Header("password") String password); The Observable who make the login to the API:public Observable signIn(String user, String pass) { return netService.signIn(user, pass).flatMap(new Func1() { @Override public Observable call(final Response accountEntityResponse) { AccountEntity accountEntity = accountEntityResponse.body(); diskAccountDataStore.createAccount(accountToAccountEntityMapper.reverseMap(accountEntity)).subscribe(); return Observable.create(new Observable.OnSubscribe() { @Override public void call(Subscriber
Read More